Search code examples
androidkotlinmapbox-android

While user tracking is on zoom on user location


I am using the version of mapbox-android-sdk and mapbox-android-plugin-locationlayer

// Mapbox
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.6.1'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.11.0'

One problem I am facing is, once I enable user tracking by setting cameraMode to TRACKING like below:

mapboxMap.locationComponent.cameraMode = CameraMode.TRACKING

When I zoom in/out into the map the zoomed location changes from the user tracked position to the pinched/zoomed location of the screen.

Any idea on how to zoom in/out and keep the tracked user location centered and tracking enabled?


Solution

  • When you activate your location component, you can add LocationComponentOptions with trackingGesturesManagement enabled

    val options = LocationComponentOptions.builder(context)
        .trackingGesturesManagement(true)
        .build()
    mapboxMap?.locationComponent?.activateLocationComponent(context!!, options)
    

    https://www.mapbox.com/android-docs/api/map-sdk/6.6.0/com/mapbox/mapboxsdk/location/LocationComponentOptions.html#trackingGesturesManagement--