3

I am migrating an existing app to work with iOS 9, there was not much to change but adding ATS to the info.plist and use MKAnnotationView instead of MKPinAnnotationView for custom pins on the map. The problem was when starting to test the changes, I noticed the location updates were too frequent, even when I'm standing still. Nothing has been changed in the way the location manager is initialized.

Here is a small sample of the log.

2015-09-25 12:16:25.462 MyApp[2009:911066] location: <+39.09040164,-77.52540765> +/- 65.00m (speed -1.00 mps / course -1.00) @ 9/25/15, 12:16:25 PM Eastern Daylight Time 

2015-09-25 12:16:25.464 MyApp[2009:911066] location: <+39.09040164,-77.52540765> +/- 65.00m (speed -1.00 mps / course -1.00) @ 9/25/15, 12:16:25 PM Eastern Daylight Time 

2015-09-25 12:16:25.468 MyApp[2009:911066] location: <+39.09040164,-77.52540765> +/- 65.00m (speed -1.00 mps / course -1.00) @ 9/25/15, 12:16:25 PM Eastern Daylight Time 

2015-09-25 12:16:25.475 MyApp[2009:911066] location: <+39.09040164,-77.52540765> +/- 65.00m (speed -1.00 mps / course -1.00) @ 9/25/15, 12:16:25 PM Eastern Daylight Time 

The location manager is set like this

    locationManager = [CLLocationManager new];

    locationManager.delegate = self;
    locationManager.distanceFilter = 25.0f;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

    if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
       [locationManager requestAlwaysAuthorization];
    }
    [locationManager startUpdatingLocation];

I guess the question is: is there something wrong with my implementation or was there a change in the Core Location API that is ignoring the distance filter?

quant24
  • 393
  • 6
  • 22
  • Is the property `pausesLocationUpdatesAutomatically` on `CLLocationManager` set to `YES`? If set to `YES`, it helps improving the battery life by disabling location updates if the location data is unlikely to change. – Matteo Pacini Sep 28 '15 at 17:17
  • @MatteoPacini It is never set to `NO` at any point in code, the default value is `YES`. I'll try explicitly setting it to `YES`. Thanks. – quant24 Sep 28 '15 at 17:21
  • @MatteoPacini I tried it, didnt make any difference. thanks tho. – quant24 Sep 28 '15 at 20:08

1 Answers1

2

In the locationManager:didUpdateLocations: method the distanceFilter property of CLLocationManager was was being reset depending on the speed, in iOS 9 this seems to trigger a new location update (returning the last known location), thus resulting on hundreds of new location updates in a few seconds.

quant24
  • 393
  • 6
  • 22
  • 1
    Interesting. As soon as you are able you should accept your own answer so other readers know the problem is solved. – Duncan C Sep 28 '15 at 21:46
  • 1
    I see the same kind of results but I'm not changing anything to the locationmanager after starting it. Can you have a look at http://stackoverflow.com/questions/32838488/cllocationmanager-in-ios9-giving-incorrect-locations-ios8-is-ok perhaps ? – Sjoerd Perfors Sep 30 '15 at 07:28
  • 1
    @SjoerdPerfors I think our issues with `CLLocationManager` are a little different, my problem wasn't related to bad location data, but **extremely** frequent updates. – quant24 Sep 30 '15 at 20:07