Skip to content

Instantly share code, notes, and snippets.

@utsmannn
Created June 24, 2020 10:55
Show Gist options
  • Save utsmannn/3430d8c95c265ccd11057987b6d5d294 to your computer and use it in GitHub Desktop.
Save utsmannn/3430d8c95c265ccd11057987b6d5d294 to your computer and use it in GitHub Desktop.
fun rotateMarker(marker: Marker, toRotation: Float) {
val handler = Handler()
val start = SystemClock.uptimeMillis()
val startRotation = marker.rotation
val duration: Long = 300
handler.post(object : Runnable {
override fun run() {
val elapsed = SystemClock.uptimeMillis() - start
val t = LinearInterpolator().getInterpolation(elapsed.toFloat() / duration)
val rot = t * toRotation + (1 - t) * startRotation
marker.rotation = if (-rot > 180) rot / 2 else rot
if (t < 1.0) {
handler.postDelayed(this, 16)
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment