Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

setTargetCoordinate seems to be incompatible with mapViewUserLocationAnchorPoint #13570

Closed
stoeffn opened this issue Dec 13, 2018 · 12 comments
Closed
Assignees
Labels
iOS Mapbox Maps SDK for iOS support

Comments

@stoeffn
Copy link

stoeffn commented Dec 13, 2018

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.

Steps to reproduce

  1. Set-up a map view and delegate
  2. Return non-center (e.g. bottom) position as user location anchor point
  3. Set a target coordinate

Expected behavior

Map view focuses on both the user location, which is at the bottom of the view, and the target coordinate.

Actual behavior

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.

Screenshot

Configuration

Mapbox SDK versions: 4.6
iOS versions: 12.1
Device models: iPhone 6 Plus
Xcode version: 10.1

@julianrex
Copy link
Contributor

julianrex commented Dec 13, 2018

Thanks for the bug report @stoeffn! Any chance you can share a video/gif of what you're seeing? Thanks!

@julianrex julianrex added bug iOS Mapbox Maps SDK for iOS labels Dec 13, 2018
@stoeffn
Copy link
Author

stoeffn commented Dec 13, 2018

Sure, Julian!
Here is a video with target coordinate enabled and here is a video without.

@fabian-guerra fabian-guerra self-assigned this Jan 22, 2019
@fabian-guerra
Copy link
Contributor

Hi, @stoeffn. Thank you for using Mapbox. I was trying to reproduce this error with no luck.

My questions are:

  • Do you run often setTargetCoordinate?
  • Could you please provide a code snippet or test app we could use to track down this issue?

@stoeffn
Copy link
Author

stoeffn commented Jan 26, 2019

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 😃

@stoeffn
Copy link
Author

stoeffn commented Jan 28, 2019

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!

@fabian-guerra
Copy link
Contributor

Hi, @stoeffn. Thank you for the test project. I will take a second look.

@fabian-guerra fabian-guerra added support and removed bug labels Jan 29, 2019
@fabian-guerra
Copy link
Contributor

fabian-guerra commented Jan 29, 2019

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.

@stoeffn
Copy link
Author

stoeffn commented Feb 2, 2019

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?

@fabian-guerra
Copy link
Contributor

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.

@stoeffn
Copy link
Author

stoeffn commented Feb 26, 2019

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?

@1ec5
Copy link
Contributor

1ec5 commented Mar 6, 2019

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.

@fabian-guerra
Copy link
Contributor

Hi, @stoeffn.

Please take a look at the comment above. Specially look at the approach taken in #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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
iOS Mapbox Maps SDK for iOS support
Projects
None yet
Development

No branches or pull requests

4 participants