1

I'm trying to understand why locationManager continues to provide updates after I've called stopUpdatingLocation()

extension ActionViewController: CLLocationManagerDelegate {
    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let newLocation: CLLocation = locations.last!
        print("New Location Accuracy is: \(newLocation.horizontalAccuracy)")
        print("Desired Accuracy is: \(locationManager.desiredAccuracy)")
        if newLocation.horizontalAccuracy < 0 {
            return
        }

        if newLocation.horizontalAccuracy <= locationManager.desiredAccuracy {
            print("We are shutting down location manager")
            locationManager.stopUpdatingLocation()
            currentLocation = newLocation
        let camera = GMSCameraPosition.camera(withLatitude: newLocation.coordinate.latitude,
                                              longitude: newLocation.coordinate.longitude,
                                              zoom: zoomLevel)
...

Print out from debug area: New Location Accuracy is: 10.0 Desired Accuracy is: 10.0 We are shutting down location manager New Location Accuracy is: 10.0 Desired Accuracy is: 10.0 We are shutting down location manager New Location Accuracy is: 10.0 Desired Accuracy is: 10.0 We are shutting down location manager New Location Accuracy is: 702.317035988665 Desired Accuracy is: 10.0 New Location Accuracy is: 702.318123337466 Desired Accuracy is: 10.0 New Location Accuracy is: 10.0 Desired Accuracy is: 10.0 We are shutting down location manager

Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55

1 Answers1

0

I've spent many hours searching for the answer and I believe I've found it. Apparently, after calling stopUpatingLocation, it takes a few seconds for the GPS antennae to power down. Someone posted that this was discussed at a WWDC.

Here is the post

Community
  • 1
  • 1
Martin Muldoon
  • 3,388
  • 4
  • 24
  • 55