Skip to content

Instantly share code, notes, and snippets.

@iRYO400
Last active July 17, 2018 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iRYO400/d5dfb8d9b380ff29778595f812808230 to your computer and use it in GitHub Desktop.
Save iRYO400/d5dfb8d9b380ff29778595f812808230 to your computer and use it in GitHub Desktop.
A-snippet #1 - Smoothing Marker rotating in Google Maps
/**
* Smooth rotating my location marker arrow
* @param marker - marker itself
* @param newBearing - new direction to rotate
*/
private fun changeBearingSmoothly(marker: Marker?, newBearing: Float) {
if (marker == null) {
return
}
val animation = ValueAnimator.ofFloat(0f, 100f)
var previousStep = 0f
val deltaLatitude = newBearing - marker.rotation
animation.duration = 1000
animation.addUpdateListener { updatedAnimation ->
val deltaStep = updatedAnimation.animatedValue as Float - previousStep
previousStep = updatedAnimation.animatedValue as Float
marker.rotation = (marker.rotation + deltaLatitude * deltaStep * 1 / 100)
}
animation.start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment