Stopping user location updates (blue dot) for MKMapview

I am using an instance of CLLocationManager as well as MKMapView for my application. I have a button that, when clicked, triggers the startUpdatingLocation of my location manager, which allows me to receive new location updates via the didUpdateToLocation callback. I stop these updates when I'm satisfied with the accuracy:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

      

The problem is that the GPS stays on as indicated by the arrow in the upper right corner of the status bar. Upon further investigation, I realized that it was because the mapView shows UserLocation = YES, which means it will keep receiving updates even if my own locationManager instance stopped updating.

Adding the following after my stop of updates turns off the GPS sign, but the blue dot obviously disappears (but I want the current position to still be rendered).

mapView.showsUserLocation = NO;

      

For my application, I need to use CLLocationManager (to calculate the nearest POIs at a certain distance) and MKMapView (mainly to display these POIs as annotations around my localization). Is there a way to just stop all GPS updates for both, and just freeze the blue dot at this point?

I was thinking about disabling mapView.showsUserLocation completely and pulling CLLocation from LocationManager to mapView as custom annotation, but I'm not sure if this is the best way. Any ideas?

+3


source to share


1 answer


I think that after you finish updating the location to the desired precision, resetting the annotation pin will be visual enough for the user to know the selected location. This is pretty standard among MKMapView usages.



Another thing to think about, the location arrow actually persists for a period of time (depending on the type of use), even after you stop monitoring the location. You can find out how long it lasts in Apple's Hosting Guide, but it's also something to consider.

+1


source







All Articles