iOS: Follow With Heading tracking mode is being reset after next location update
I am setting the userTackingMode to MGLUserTrackingModeFollowWithHeading
After the first location update, the tracking mode is being reset to MGLUserTrackingModeNone and the map no longer tracks to the user's location.
Dupe of #1145. The workaround is to set a valid coordinate before setting the user tracking mode.
This might be little different. I am not doing this at startup and I am setting a center location for the map. I will reword the title to make more sense.
@picciano In what order are you setting everything and at what base zoom level? There are a lot of landmines in the various setZoomLevel or setCenterCoordinate methods that will reset to MGLUserTrackingModeNone.
One bug that I consistently see is when any MGLUserTrackingMode is enabled and the user zooms out beyond round(self.zoomLevel) >= 10, the eventual call to [MGLMapView setCenterCoordinate:zoomLevel:animated:] resets the tracking mode.
It seems to me that the forced zoom back to the accuracy range (often z18) when you were trying to zoom out is a somewhat annoying and unexpected behavior in the first place, but that's a different topic.
At startup:
// Create the map view...
self.mapView = [[MGLMapView alloc] initWithFrame:self.view.bounds accessToken:kMapboxPublicAccessToken];
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MGLUserTrackingModeNone;
self.mapView.rotateEnabled = NO;
self.mapView.delegate = self;
[self setTallyGoStyle];
[self.view insertSubview:self.mapView atIndex:0];
[self.mapView setCenterCoordinate:kLosAngeles.coordinate zoomLevel:12 animated:YES];
User event triggers:
self.mapView.userTrackingMode = MGLUserTrackingModeFollow;
Another user event triggers:
self.mapView.userTrackingMode = MGLUserTrackingModeNone;
self.mapView.rotateEnabled = !self.mapView.rotateEnabled; // is YES now
Another user event triggers:
self.mapView.userTrackingMode = MGLUserTrackingModeFollowWithHeading;
The settings stays set for less than one second, then reverts back to MGLUserTrackingModeNone after the next location update.
@friedbunny So, yes the zoom level is at 12 (set by code). MGLUserTrackingModeFollow works fine. MGLUserTrackingModeFollowWithHeading resets to MGLUserTrackingModeNone.
Thanks for the walk-through @picciano, I'm going to take a look at this today.
I can't reproduce this on device or in simulator — I'm using actionsheet buttons to instigate the progression you outlined but the tracking mode stays properly set throughout.
I am still seeing it, but I will see if I can isolate it better and provide a demo.
Okay, I think I see what's going on. In my map delegate, I implement the didUpdateUserLocation: method. In that method, I call the setDirection: method of the map view, which turns off user tracking as a side effect.
If that's how it's supposed to work, then we're fine and this can be closed.
@picciano If you set userTrackingMode to MGLUserTrackingModeFollowWithHeading, -[MGLMapView locationManager:didUpdateHeading:] already takes care of rotating the map for you.
Hello Guys,
My application getting crashes most of the time while we using self.mapView.userTrackingMode

Please let me know How can i resolve the crash issue?