I have an MKMapView with an MKUserTrackingBarButtonItem. The user’s current location should only be displayed in the Follow or FollowWithHeading modes. The implementation looks like this:
- (void)mapView:(MKMapView *)mapView
didChangeUserTrackingMode:(MKUserTrackingMode)mode
animated:(BOOL)animated
{
[mapView setShowsUserLocation:(mode != MKUserTrackingModeNone)];
}
This is the only place in my code where setShowsUserLocation is called and it works as expected when the MKUserTrackingBarButtonItem is pressed.
My problem occurs when the UserTrackingMode is changed by dragging the map: in this case, the “blue dot” annotation disappears as intended, but in about 20% of cases it reappears when dragging has ended.
If I then test for the map’s showsUserLocation property, it is always set to NO, even though the “blue dot” annotation is visible.
I’d be very grateful for help if you know how to solve this.
Looks like if a user location update comes in at a certain time during the drag, the
didUpdateUserLocationdelegate method still fires and the blue dot re-appears even thoughshowsUserLocationisNO.This appears to be a shortcoming of the map view.
Toggling
showsUserLocationindidUpdateUserLocationseems to fix the map view’s internal state and the blue dot goes away: