ios - 如何在后台快速跟踪用户位置

标签 ios swift google-maps background userlocation

我正在尝试在后台跟踪用户位置 我曾尝试在 In us with 和 without always 时使用,但每次我最小化应用程序时,位置图标都会消失 我在教程中读过它应该显示蓝色条,但我是没有得到那个栏我也检查了更新位置的后台模式

  map.showsUserLocation = true
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyBest
    locationManager.requestWhenInUseAuthorization()
    locationManager.requestAlwaysAuthorization()
    locationManager.startUpdatingLocation()
    // Do any additional setup after loading the view, typically from a nib.
    alwaysAuthorization()
}

func alwaysAuthorization(){
    if CLLocationManager.locationServicesEnabled() && CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
        locationManager.requestAlwaysAuthorization()
    }
}


func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations.last
    let region  = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude), span: MKCoordinateSpan (latitudeDelta: 0.2, longitudeDelta: 0.2))
    self.map.region = region
    print("location \(location!.coordinate.latitude) and \(location!.coordinate.longitude)")
}

最佳答案

这就是我要找的

        locationManager.allowsBackgroundLocationUpdates = true

关于ios - 如何在后台快速跟踪用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53814801/

相关文章:

objective-c - 这是对 NSNotificationCenter 的有效使用吗

ios - 翠鸟图像采用全宽

swift - 如何使用弹出按钮(或下拉按钮)创建交互式菜单

iOS EXC_BAD_ACCESS,但没有什么是零

ios - 如何处理 NSData contentsOfURL EXC_BREAKPOINT 错误

javascript - 未选择自动完成选项时如何禁用输入 : Google Maps SearchBox

javascript - 修复哎呀出了点问题!在谷歌地图 API 中

google-maps - React-google-maps 重新渲染问题

objective-c - MAX在Objec-C/cocos2d中的作用是什么?

ios - Apple App 因非 native 按钮和功能而被拒绝