Guest User

Untitled

a guest
Jul 17th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /**
  2. * Smooth moving my location marker arrow
  3. * @param marker - marker itself
  4. * @param newLatLng - new location to move
  5. */
  6. private fun changePositionSmoothly(marker: Marker?, newLatLng: LatLng) {
  7. if (marker == null) {
  8. return
  9. }
  10. val animation = ValueAnimator.ofFloat(0f, 100f)
  11. var previousStep = 0f
  12. val deltaLatitude = newLatLng.latitude - marker.position.latitude
  13. val deltaLongitude = newLatLng.longitude - marker.position.longitude
  14. animation.duration = 1000
  15. animation.addUpdateListener { updatedAnimation ->
  16. val deltaStep = updatedAnimation.animatedValue as Float - previousStep
  17. previousStep = updatedAnimation.animatedValue as Float
  18. marker.position = LatLng(marker.position.latitude + deltaLatitude * deltaStep * 1 / 100, marker.position.longitude + deltaStep * deltaLongitude * 1 / 100)
  19. }
  20. animation.start()
  21. }
Add Comment
Please, Sign In to add comment