mapbox / mapbox-gl-native-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL
https://mapbox.com/mobile
Other
218 stars 114 forks source link

Center to user location #740

Closed Guimareshh closed 1 year ago

Guimareshh commented 1 year ago

Hello,

I'm doing a migration from Android SDK v9 to v10, and I'm trying to understand how to center on user's location at runtime. Here's a piece of code I'm trying to migrate:

when (locationMode) {
    LocationMode.Approximate, LocationMode.FocusedOnUser  -> {
        locationComponent.cameraMode = CameraMode.TRACKING_GPS_NORTH
        locationComponent.renderMode = RenderMode.NORMAL
    }
    LocationMode.Tracking -> {
        locationComponent.cameraMode = CameraMode.TRACKING_COMPASS
        locationComponent.renderMode = RenderMode.COMPASS
    }
}

I have been able to migrate the camera mode for tracking user's location with the viewport plugin, but I'm not sure what is the best option to center on user location:

 when (locationMode) {
    LocationMode.Approximate, LocationMode.FocusedOnUser -> {
        //TODO mapboxMap.centerTo(user.location)
    }
    LocationMode.Tracking -> {
        mapView.viewport.apply {
            transitionTo(
                makeFollowPuckViewportState(
                    FollowPuckViewportStateOptions
                        .Builder()
                        .pitch(0.0)
                        .zoom(MapBoxUtils.DEFAULT_ZOOM)
                        .build()
                )
            )
        }
    }
}