I'm working on an Android map app with a location button that animates the camera to the user's location and follows their movement. However, when the user is in motion (e.g., driving), there's a noticeable jump in the map's position after the animation completes. This occurs because the user's location changes while the animation is in progress. I thought of updating dynamically the target value of the pending animation, however, I'm afraid this is not possible in Mapbox.
Here's a snippet of my code:
var isAnimating = false
val initialOptions = CameraOptions.Builder()
.center(currentUserPosition)
.build()
val animationOptions = MapAnimationOptions.Builder()
.duration(600)
.animatorListener(animationListener) // listener updates isAnimating flag
.build()
map.easeTo(initialOptions, animationOptions)
location.addOnIndicatorPositionChangedListener {
if (!isAnimating) {
val options = CameraOptions.Builder()
.center(it)
.build()
map.setCamera(options)
gestures.focalPoint = map.pixelForCoordinate(it)
}
}
I'm seeking advice on how to make the camera smoothly follow the user's movement without the noticeable jump after the animation finishes. Any insights or ideas would be greatly appreciated.
to avoid the jump after the animation, you can update the camera's position in real-time based on the user's location updates.