Error showUserLocation behavior in MKMapView

I have MKMapView with MKUserTrackingBarButtonItem . The user's current location should only be displayed in Follow or FollowWithHeading . The implementation is as follows:

 - (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 setShowsUserLocation and works as expected when MKUserTrackingBarButtonItem .

My problem arises when the UserTrackingMode changed by dragging the map: in this case the blue dot annotation disappears as intended, but in about 20% of cases it appears when the dragging is completed.

If you then check the map showsUserLocation property, it will always be NO, even though the blue dot annotation is visible.

I would be very grateful for the help if you know how to solve this.

+2
source share
1 answer

It appears that if the user’s location update occurs at a specific time during drag and drop, the didUpdateUserLocation delegate method still fires and the blue dot reappears, although showsUserLocation is NO .

This is apparently a drawback to the map view.

Switching showsUserLocation to didUpdateUserLocation like fixing the internal state of the map display, and the blue dot disappears:

 -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { if (!mapView.showsUserLocation) { mapView.showsUserLocation = YES; mapView.showsUserLocation = NO; } } 
+1
source

All Articles