Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. public void animateMarkerList( final Marker marker,
  2. final boolean hideMarker,
  3. final List<LatLng> lista) {
  4. final Handler handler = new Handler();
  5. final long start = SystemClock.uptimeMillis();
  6. Projection proj = mMap.getProjection();
  7. Point startPoint = proj.toScreenLocation(marker.getPosition());
  8. final LatLng startLatLng = proj.fromScreenLocation(startPoint);
  9. final long duration = 1000;//1 second
  10.  
  11. final LatLng toPosition = lista.get(0);
  12.  
  13. final Interpolator interpolator = new LinearInterpolator();
  14.  
  15. handler.post(new Runnable() {
  16. @Override
  17. public void run() {
  18. long elapsed = SystemClock.uptimeMillis() - start;
  19. float t = interpolator.getInterpolation((float) elapsed
  20. / duration);
  21. double lng = t * toPosition.longitude + (1 - t) * startLatLng.longitude;
  22. double lat = t * toPosition.latitude + (1 - t) * startLatLng.latitude;
  23. marker.setPosition(new LatLng(lat, lng));
  24.  
  25. if (t < 1.0) {
  26. // Post again 16ms later.
  27. handler.postDelayed(this, 16);
  28. } else {
  29.  
  30. lista.remove(0);
  31. if(lista.size()>0){
  32. animateMarkerList(marker,hideMarker,lista);
  33. }
  34. else{
  35. if (hideMarker) {
  36. marker.setVisible(false);
  37. } else {
  38. marker.setVisible(true);
  39. }
  40. }
  41.  
  42. }
  43. }
  44. });
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement