How to fixed the mapbox navigation puck's position and direction

1k views Asked by At

With the default mapbox navigation following mode, the puck will move to many positions on the screen and in many direction.
How can I align it to center horizontal in bottom of the screen and the direction always point to top? Then only the map move, zoom and rotate.

I tried to override followingPitchPropertyOverride and followingZoomPropertyOverride. The puck will fixed in bottom but the direction is not always point to top (the direction is depend on the remain route).

enter image description here

https://docs.mapbox.com/android/navigation/guides/migrate-to-v2/#control-pucks-position-on-screen

2

There are 2 answers

2
Yury On

You can follow the example in mapbox-navigation-android/examples/MapboxCameraAnimationsActivity.kt.

Need to use com.mapbox.navigation.ui.maps.camera.NavigationCamera

val viewportDataSource = MapboxNavigationViewportDataSource(
            mapView.getMapboxMap()
        )
val navigationCamera = NavigationCamera(
            mapView.getMapboxMap(),
            mapView.camera,
            viewportDataSource
        )
// set following mode to navigation camera
navigationCamera.requestNavigationCameraToFollowing()
0
Linh On

There is a property maximizeViewableGeometryWhenPitchZero in FollowingFrameOptions, set it to false will make the puck always align at bottom (instead of move to many positions in map).

package com.mapbox.navigation.ui.maps.camera.data
class FollowingFrameOptions internal constructor() {
    ....

    /**
     * When a produced **following frame** has pitch `0` and there are at least 2 points available for framing,
     * the puck will not be tied to the bottom edge of the [MapboxNavigationViewportDataSource.followingPadding] and instead move
     * around the centroid of the framed geometry (user location plus additional points to frame together or maneuver if route is available)
     * to maximize the view of that geometry within the [MapboxNavigationViewportDataSource.followingPadding].
     *
     * Defaults to `true`.
     */
    var maximizeViewableGeometryWhenPitchZero = true

use

viewportDataSource.options.followingFrameOptions.maximizeViewableGeometryWhenPitchZero = false

And, to make the puck bearing be fixed to location's bearing

viewportDataSource.options.followingFrameOptions.bearingSmoothing.apply {
    enabled = false
}

Then, the result will look like

enter image description here