mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
478 stars 134 forks source link

Location puck bearing direction is wrong in version 11 of mapbox sdk for android #2466

Closed arbonvata closed 2 months ago

arbonvata commented 2 months ago

Environment

Observed behavior and steps to reproduce

Given the following code:

with(mapView) {
                location.locationPuck = createDefault2DPuck(withBearing = true)
                location.enabled = true
                location.puckBearing = PuckBearing.COURSE
                viewport.transitionTo(
                    targetState = viewport.makeFollowPuckViewportState(
                        options = FollowPuckViewportStateOptions.Builder()
                            .bearing(options = FollowPuckViewportStateBearing.SyncWithLocationPuck)
                            .build()
                    ),
                    transition = viewport.makeImmediateViewportTransition()
                )
                location.addOnIndicatorPositionChangedListener(onIndicatorPositionChangedListener)

            }

and also

  private val onIndicatorPositionChangedListener = OnIndicatorPositionChangedListener {
        // Jump to the current indicator position
        binding.mapView.mapboxMap.setCamera(CameraOptions.Builder().bearing(0.0).build())
        // Set the gestures plugin's focal point to the current indicator location.
        binding.mapView.gestures.focalPoint = binding.mapView.mapboxMap.pixelForCoordinate(it)
    }

Have tried to remove the location.addOnIndicatorPositionChangedListener and replaced with

  with(mapView) {
                location.locationPuck = createDefault2DPuck(withBearing = true)
                location.enabled = true
                location.puckBearing = PuckBearing.COURSE
                viewport.transitionTo(
                    targetState = viewport.makeFollowPuckViewportState(
                        options = FollowPuckViewportStateOptions.Builder()
                            .bearing(options = FollowPuckViewportStateBearing.SyncWithLocationPuck)
                            .build()
                    ),
                    transition = viewport.makeImmediateViewportTransition()
                )

            }
            mapboxMap.setCamera(CameraOptions
                .Builder()
                .bearing(90.0)
                .zoom(2.2)
                .build()
            )

without any impact Changing bearing on CameraOptions.Builder().bearing doesn't have any impact at all. I have played with values 0, 90, 180 and 270. No visible impact at all

Same with location.puckBearing = PuckBearing.HEADING. No impact at all

See the attached file. We are moving from right to the left in the image

Expected behavior

The location puck should have the same direction as the movement

Notes / preliminary analysis

I have followed the recommendation from the official tutorials, and I guess that the attached code is correct

Additional links and references

screen

natiginfo commented 2 months ago

Thanks for reporting the issue. We will take a look at it.

pengdev commented 2 months ago

Hi @arbonvata, I think you are missing location.puckBearingEnabled = true in your code snippet. In your case the puck bearing is not enabled at all, and please also note that once you are in FollowPuckViewportState, the camera bearing is driven by the viewport plugin(updated every frame), so the setCamera you pragmatically call will be overwritten by FollowPuckViewportState immediately. To be able to take over the bearing pragmatically while in FollowPuckViewportState, you will need to set FollowPuckViewportStateOptions.Builder().bearing(null).build().

arbonvata commented 2 months ago

Thanks for the help. It works now