Last active
July 17, 2018 07:28
-
-
Save iRYO400/5c0a5d97dd451fdcb79a889ccefbb9e1 to your computer and use it in GitHub Desktop.
A-snippet #1 - Smoothing Marker moving in Google Maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Smooth moving my location marker arrow | |
* @param marker - marker itself | |
* @param newLatLng - new location to move | |
*/ | |
private fun changePositionSmoothly(marker: Marker?, newLatLng: LatLng) { | |
if (marker == null) { | |
return | |
} | |
val animation = ValueAnimator.ofFloat(0f, 100f) | |
var previousStep = 0f | |
val deltaLatitude = newLatLng.latitude - marker.position.latitude | |
val deltaLongitude = newLatLng.longitude - marker.position.longitude | |
animation.duration = 1000 | |
animation.addUpdateListener { updatedAnimation -> | |
val deltaStep = updatedAnimation.animatedValue as Float - previousStep | |
previousStep = updatedAnimation.animatedValue as Float | |
marker.position = LatLng(marker.position.latitude + deltaLatitude * deltaStep * 1 / 100, marker.position.longitude + deltaStep * deltaLongitude * 1 / 100) | |
} | |
animation.start() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment