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
452 stars 127 forks source link

Compass is not working as we move the device #2047

Open asifjavaid opened 1 year ago

asifjavaid commented 1 year ago

Environment

Observed behavior and steps to reproduce

We are migrating our old app with legacy SDK version 8.xxx to latest mapbox SDK. The map is not stable. Its compass is keep on rotating.

Expected behavior

We want the behaviour like legacy SDK works, like, as we move the device the compass should rotate the map accordingly with correct bearing angle. Please suggest.

Notes / preliminary analysis

Here is my initials settings of code in kotlin.

` private fun initLocationComponent() { val locationComponentPlugin = mapView!!.location locationComponentPlugin.updateSettings { this.enabled = true this.locationPuck = LocationPuck2D( bearingImage = AppCompatResources.getDrawable( this@MapBoxBaseActivity, R.drawable.mapbox_user_puck_icon, ), shadowImage = AppCompatResources.getDrawable( this@MapBoxBaseActivity, R.drawable.mapbox_user_icon_shadow, ), /scaleExpression = interpolate { linear() zoom() stop { literal(0.0) literal(0.6) } stop { literal(20.0) literal(1.0) } }.toJson()/ ) } locationComponentPlugin.addOnIndicatorPositionChangedListener(onIndicatorPositionChangedListener) locationComponentPlugin.addOnIndicatorBearingChangedListener(onIndicatorBearingChangedListener) mapView!!.gestures.addOnMoveListener(onMoveListener) mapView!!.compass.getSettings().fadeWhenFacingNorth = false mapView!!.compass.position = Gravity.RIGHT }

private val onIndicatorBearingChangedListener = OnIndicatorBearingChangedListener {

    mapView!!.getMapboxMap().setCamera(CameraOptions.Builder().bearing(it).build())

}
private fun onCameraTrackingDismissed() {
    Toast.makeText(this, "onCameraTrackingDismissed", Toast.LENGTH_SHORT).show()
    mapView!!.location
        .removeOnIndicatorPositionChangedListener(onIndicatorPositionChangedListener)
    mapView!!.location
        .removeOnIndicatorBearingChangedListener(onIndicatorBearingChangedListener)
    mapView!!.gestures.removeOnMoveListener(onMoveListener)
}
private val onMoveListener = object : OnMoveListener {
    override fun onMoveBegin(detector: MoveGestureDetector) {
        onCameraTrackingDismissed()
    }

    override fun onMove(detector: MoveGestureDetector): Boolean {
        return false
    }

    override fun onMoveEnd(detector: MoveGestureDetector) {}
}
private val onIndicatorPositionChangedListener = OnIndicatorPositionChangedListener {

    location = Location("")
    location!!.latitude = it.latitude();
    location!!.longitude = it.longitude();

    mapView!!.getMapboxMap().setCamera(CameraOptions.Builder().center(it).build())
    mapView!!.gestures.focalPoint = mapView!!.getMapboxMap().pixelForCoordinate(it)
    //stopLocationUpdates()
}`

Additional links and references

yunikkk commented 1 year ago

@asifjavaid what compass mode are you using? In the example activity you can see how the modes are switched.

asifjavaid commented 1 year ago

@yunikkk Hi thank you for your response. We have not set any mode. It is with its default settings. Which mode we need to set to make it work?