mapbox-navigation-ios
mapbox-navigation-ios copied to clipboard
mapViewUserAnchorPoint on NavigationViewControllerDelegate has no effect.
Test App Repo: (This is essentially just Mapboxes tutorial app) https://github.com/JustinmClapperton/mapboxIosTest
Example Video: https://drive.google.com/file/d/1jy2JCdjmXaUqwlBGw9pW-RWSU9BrwtoB/view?usp=sharing
Mapbox Navigation SDK version:
1.4.0
Steps to reproduce
- Open application
- Long press on destination
- Press Start Navigation
- Notice the use puck anchor hasnt changed
Expected behavior
User puck should be at the location define in
func navigationViewController(_ navigationViewController: NavigationViewController, mapViewUserAnchorPoint mapView: NavigationMapView) -> CGPoint {
return CGPoint(x: 100, y: 100)
}
Actual behavior
The user puck does not move at all as if the above method is completely ignored. It seems that it isnt passed through to the underlying MapView.
Any advice on a work around for this if possible would be much appreciated.
I have same issue in MapBox navigation version 1.4. I verified the code and it simply never gets called.
The problem is in the code int NavigationMapView
public func updateCourseTracking(location: CLLocation?, camera: MGLMapCamera? = nil, animated: Bool = false) {
// While animating to overhead mode, don't animate the puck.
let duration: TimeInterval = animated && !isAnimatingToOverheadMode ? 1 : 0
animatesUserLocation = animated
userLocationForCourseTracking = location
guard let location = location, CLLocationCoordinate2DIsValid(location.coordinate) else {
return
}
let centerUserCourseView = { [weak self] in
guard let point = self?.convert(location.coordinate, toPointTo: self) else { return }
self?.userCourseView.center = self?.userAnchorPoint ?? point
}
if tracksUserCourse {
centerUserCourseView()
let newCamera = camera ?? MGLMapCamera(lookingAtCenter: location.coordinate, altitude: altitude, pitch: 45, heading: location.course)
let function: CAMediaTimingFunction? = animated ? CAMediaTimingFunction(name: .linear) : nil
setCamera(newCamera, withDuration: duration, animationTimingFunction: function, completionHandler: nil)
} else {
// Animate course view updates in overview mode
UIView.animate(withDuration: duration, delay: 0, options: [.curveLinear], animations: centerUserCourseView)
}
userCourseView.update(location: location, pitch: self.camera.pitch, direction: direction, animated: animated, tracksUserCourse: tracksUserCourse)
}
The userAnchorPoint is added by me. I will create a pr.
@JustinmClapperton, this functionality was re-worked in Navigation SDK for iOS 2.0.0. Would you be able to upgrade and try it out? We also provide some docs related to new camera behavior in this guide.
There is the ability to change certain camera options via FollowingCameraOptions, OverviewCameraOptions, but we do not currently provide a way to change anchor point specifically. If you feel that new implementation can be extended with functionality you'd like to achieve, please describe it in more detail and we can consider implementing it.
Hi
We haven’t been able to upgrade as 2.0.0 no longer supports Carthage :(. Hopefully you will in the future or one day when we are able to upgrade to use SPM.
Thanks for the update though.
On Mon, Nov 15, 2021 at 12:46 Maxim Makhun @.***> wrote:
@JustinmClapperton https://github.com/JustinmClapperton, this functionality was re-worked in Navigation SDK for iOS 2.0.0 https://github.com/mapbox/mapbox-navigation-ios/releases/tag/v2.0.0. Would you be able to upgrade and try it out? We also provide some docs related to new camera behavior in this guide https://docs.mapbox.com/ios/navigation/guides/map-and-camera/navigation-camera/ .
There is the ability to change certain camera options via FollowingCameraOptions, OverviewCameraOptions, but we do not currently provide a way to change anchor point specifically. If you feel that new implementation can be extended with functionality you'd like to achieve, please describe it in more detail and we can consider implementing it.
— You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-navigation-ios/issues/2923#issuecomment-969305857, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMAPPKCP2D2DQWODSCHFELUMFWS5ANCNFSM42ZWZZLA .
Hi @MaximAlien, I was able to upgrade but ill show a screenshot of my issue and why we need to change anchor point. There is also in inconsistency of the anchor point as when I initially start navigation the anchor is in the center of screen and is in a place that makes sense but then if I switch between overview and follow the new anchor point is at the bottom of the screen as seen in the attached screenshot. Ive attached a screenshot of when I first start a route as well when the anchor is in the ideal place.

Hello @JustinmClapperton. I do not fully understand your use case, but looks like (based on second screenshot you've provided) issue is that bottom sheet overlaps with UserCourseView. We do not currently provide the ability to change anchor of the MapView object via Navigation Camera APIs (reason for this is that other options rely on it, e.g. pitch change near maneuver etc), but you can change MapView.padding to a custom value (based on a progress along the route, e.g. by listening to .routeControllerProgressDidChange notification). For example:
if let navigationViewportDataSource = navigationViewController.navigationMapView?.navigationCamera.viewportDataSource as? NavigationViewportDataSource {
navigationViewportDataSource.options.followingCameraOptions.paddingUpdatesAllowed = false
navigationViewportDataSource.followingMobileCamera.padding = UIEdgeInsets(top: 200.0, left: 10.0, bottom: 200.0, right: 10.0)
navigationViewController.navigationMapView?.navigationCamera.viewportDataSource = navigationViewportDataSource
}
This will give you the ability to change padding for your needs. At the same time we have a bit tricky logic to calculate anchor and padding (we first use original viewport padding to calculate anchor, but then replace it with a bit different value, which is basically similar padding, but with 1px height, and top coordinate, which is set to anchor's y coordinate).
If change of padding doesn't help you we can consider the possibility of changing anchor via public API. There is also, which you can uncomment to see a camera debugging view. https://github.com/mapbox/mapbox-navigation-ios/blob/81559e7da04456231df3e6eb16a10e75e7b79b48/Sources/MapboxNavigation/NavigationCamera.swift#L29-L32
If provided information doesn't help you much can you please modify posted screenshots so that they contain information regarding expected position of user coordinate/map etc? It'd be helpful with troubleshooting.