简体   繁体   中英

Stopping user location updates (the blue dot) for MKMapview

I am using an instance of CLLocationManager as well as a MKMapView for my app. I have a button that on tapped, will trigger startUpdatingLocation of my Location Manager which allows me to receive new location updates via the didUpdateToLocation callback. I stop these updates once I am satisfied with the accuracy:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

The problem is, the GPS remains turned on as indicated by the arrow sign on the top right of the status bar. After further investigation, I realized that this is due to the fact that the mapView has showsUserLocation = YES, which means it will continue to receive updates, even if my own instance of locationManager has stopped the updating.

Adding the following after my stopping of the updates turns off the GPS sign, but the blue dot obviously disappears (but I do want the current position there still for visualization).

mapView.showsUserLocation = NO;

For my app, I need to use both CLLocationManager (to compute nearest POIs within a certain distance) and MKMapView (mainly for the display of these POIs as annotations around my locatiom). Is there a way to simply stop all GPS updates to both, and just freeze the blue dot at that point?

I thought of disabling mapView.showsUserLocation totally, and drawing the CLLocation from the LocationManager to the mapView as a custom annotation, but I am not sure that is the best way. Any ideas?

I think that once you are done updating location to the desired accuracy, dropping an annotation pin would be visual enough for the user to know the location selected. That is pretty standard among MKMapView usages.

Another thing to think about, the location arrow actually persists for a period of time (depends on the kind of usage), even after you stop monitoring location. You can find how long it persists in the Location Guidelines from Apple, but just something to consider as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM