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

Nou*_*ouf 3 google-maps background userlocation ios swift

我正在尝试在后台跟踪用户位置我尝试在我们有和没有总是使用时使用,但每次我最小化应用程序时,位置图标消失我在教程中读过它应该显示蓝色条,但我没有得到酒吧我还检查了更新位置的后台模式

  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)")
}
Run Code Online (Sandbox Code Playgroud)

Nou*_*ouf 6

这就是我要找的

        locationManager.allowsBackgroundLocationUpdates = true
Run Code Online (Sandbox Code Playgroud)