Skip to content

Instantly share code, notes, and snippets.

@utsmannn
Created June 24, 2020 09:57
Show Gist options
  • Save utsmannn/3b5c074f8321cec67b0681ff03060014 to your computer and use it in GitHub Desktop.
Save utsmannn/3b5c074f8321cec67b0681ff03060014 to your computer and use it in GitHub Desktop.
fun movementAnimator(marker: Marker, newLatLng: LatLng) : ValueAnimator {
val animator = ValueAnimator.ofFloat(0f, 100f)
val deltaLatitude = doubleArrayOf(newLatLng.latitude - marker.position.latitude)
val deltaLongitude = newLatLng.longitude - marker.position.longitude
val prevStep = floatArrayOf(0f)
animator.duration = 1500
animator.addUpdateListener { animation ->
val deltaStep = (animation.animatedValue as Float - prevStep[0]).toDouble()
prevStep[0] = animation.animatedValue as Float
val latLng = LatLng(
marker.position.latitude + deltaLatitude[0] * deltaStep * 1.0 / 100,
marker.position.longitude + deltaStep * deltaLongitude * 1.0 / 100
)
marker.position = latLng
}
return animator
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment