Skip to content

Instantly share code, notes, and snippets.

@keithics
Last active April 17, 2024 01:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithics/e860c55de09d73794c7854d5a8d9f9b3 to your computer and use it in GitHub Desktop.
Save keithics/e860c55de09d73794c7854d5a8d9f9b3 to your computer and use it in GitHub Desktop.
Animated Drop Marker Kotlin
private fun startDropMarkerAnimation(marker: Marker) {
val target = marker.position
val handler = Handler()
val start = SystemClock.uptimeMillis()
val proj = mMap!!.projection
val targetPoint = proj.toScreenLocation(target)
val duration = (200 + targetPoint.y * 0.6) as Double
val startPoint = proj.toScreenLocation(marker.position)
startPoint.y = 0
val startLatLng = proj.fromScreenLocation(startPoint)
val interpolator = LinearOutSlowInInterpolator()
handler.post(object : Runnable {
override fun run() {
val elapsed = SystemClock.uptimeMillis() - start
val t = interpolator.getInterpolation((elapsed.toFloat() / duration).toFloat())
val lng = t * target.longitude + (1 - t) * startLatLng.longitude
val lat = t * target.latitude + (1 - t) * startLatLng.latitude
marker.setPosition(LatLng(lat, lng))
if (t < 1.0) {
// Post again 16ms later == 60 frames per second
handler.postDelayed(this, 16)
}
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment