Hi,
I'm really glad that Mapbox recently introduced func mapViewUserLocationAnchorPoint(_ mapView: MGLMapView) -> CGPoint in MGLMapViewDelegate. It really helps an important navigation use-case where we need to track the user but keep his/her position on the bottom of the screen.
However, it does not currently seem to work with func setTargetCoordinate(_ targetCoordinate: CLLocationCoordinate2D, animated: Bool), which sets a point of focus.
Map view focuses on both the user location, which is at the bottom of the view, and the target coordinate.
User location icon flickers between default center position and custom bottom position.
The screenshot below shows how the user location icon is displayed where it's supposed to be on the user's screen before switching back to the center where it's supposed to be on the map.
This is to say, that the map is not positioned correctly and the custom anchor and target coordinate seem to be "fighting" where to display the user location icon.

Mapbox SDK versions: 4.6
iOS versions: 12.1
Device models: iPhone 6 Plus
Xcode version: 10.1
Thanks for the bug report @stoeffn! Any chance you can share a video/gif of what you're seeing? Thanks!
Hi, @stoeffn. Thank you for using Mapbox. I was trying to reproduce this error with no luck.
My questions are:
setTargetCoordinate?Hello @fabian-guerra, thank you for investigating!
I'm setting targetCoordinate once a second. I've also tried setting it just once but the "flickering" was still there.
I'll try to put a demo together next week 😃
I've put together a simple sample project. It draws a route on a map and simulates movements on this route.
You can tap the map view and leave user tracking so you can verify that this works as it should.
I omitted course information but it doesn't work with course information either.
Thank you in advance!
Hi, @stoeffn. Thank you for the test project. I will take a second look.
Hi, @stoeffn. Thank you again for helping us track down the issue. After looking at the coordinate that is used as the target and the overall code structure I could tell you that the values that are passed cause this behavior. Let me explain:
When you set: mapView.setTargetCoordinate(self.polyline.coordinate, animated: true) means that the center of that polyline will be used to set the boundaries for the current coordinate to that center; (since this is a big route) the current point of view does not include that coordinate so the map tries to set the boundaries for the current step + the center, this happens every coordinate update, which is every second don't letting the previous animation to finish thus making this weird animation racing condition.
One solution may be precompute the view port for each route step so you can actually set the proper target coordinate.
What's the problem you are trying to solve? Maybe I could advice a different approach.
Hello @fabian-guerra,
sorry for the delay and thanks for your insights!
In my real app, which is a navigation app, I'm basically trying to show both the current position and the next turn on screen. So every time the user passes a turn, I'd set the target coordinate to the next one while the system keeps updating the current position.
Just to clarify: I (currently) cannot set the target coordinate while the user is moving?
Hi, @stoeffn.
Just to clarify: I (currently) cannot set the target coordinate while the user is moving?
The problem I see with that approach is that each route segment is not an average size, and as you already have seen you have this big changes in route's segment bounds that prompts the animation race conditions.
Have you tried to compute an average route step visual bounds? For example have an average bounds size that you can set for small/medium/large route segments so you don't have this big changes. Although for large route segments you won't be able to visualize the turning point at glance it will get displayed as you approach.
Hello @fabian-guerra,
calculating maximum bounds sounds like a good idea.
Related question: How do I change the altitude and pitch in an animated fashion while userTrackingMode is set to .followWithCourse?
In my real app, which is a navigation app, I'm basically trying to show both the current position and the next turn on screen. So every time the user passes a turn, I'd set the target coordinate to the next one while the system keeps updating the current position.
This is how targetCoordinate is designed to be used, but you shouldn’t need to set it on every location update. That would probably cause some of the “fighting” you noted above, because we don’t have the ability to smoothly merge camera transitions together: #3625. One way around that issue is to rely on Core Animation to drive the camera updates frame by frame instead of relying on the built-in camera animation functionality: #8176 #9808.
Also note that you may see some yo-yoing of the camera when setting a target coordinate while the map is tilted, due to #2259.
Hi, @stoeffn.
Please take a look at the comment above. Specially look at the approach taken in https://github.com/mapbox/mapbox-gl-native/issues/9808 that may help you to have a finer camera control.
I'm going to close this issue. Feel free to reopen if you hit a new problem.