mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

iOS: Follow With Heading tracking mode is being reset after next location update

Open picciano opened this issue 11 years ago • 11 comments

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.

picciano avatar Apr 02 '15 17:04 picciano

Dupe of #1145. The workaround is to set a valid coordinate before setting the user tracking mode.

1ec5 avatar Apr 02 '15 17:04 1ec5

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 avatar Apr 02 '15 17:04 picciano

@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.

friedbunny avatar Apr 04 '15 18:04 friedbunny

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.

picciano avatar Apr 06 '15 17:04 picciano

@friedbunny So, yes the zoom level is at 12 (set by code). MGLUserTrackingModeFollow works fine. MGLUserTrackingModeFollowWithHeading resets to MGLUserTrackingModeNone.

picciano avatar Apr 06 '15 17:04 picciano

Thanks for the walk-through @picciano, I'm going to take a look at this today.

friedbunny avatar Apr 07 '15 18:04 friedbunny

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.

friedbunny avatar Apr 07 '15 22:04 friedbunny

I am still seeing it, but I will see if I can isolate it better and provide a demo.

picciano avatar Apr 07 '15 23:04 picciano

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 avatar Apr 08 '15 15:04 picciano

@picciano If you set userTrackingMode to MGLUserTrackingModeFollowWithHeading, -[MGLMapView locationManager:didUpdateHeading:] already takes care of rotating the map for you.

1ec5 avatar Apr 08 '15 17:04 1ec5

Hello Guys, My application getting crashes most of the time while we using self.mapView.userTrackingMode
Screen Shot 2020-01-21 at 11 56 52 AM

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

rupendrag-ios avatar Jan 21 '20 06:01 rupendrag-ios