Created
November 6, 2015 16:09
-
-
Save barbeau/3f8c85e71f8cf125cafc to your computer and use it in GitHub Desktop.
This file contains 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
private void animateMarker(final Marker marker) { | |
final Handler handler = new Handler(); | |
final long startTime = SystemClock.uptimeMillis(); | |
final long duration = 300; // ms | |
Projection proj = mMap.getProjection(); | |
final LatLng markerLatLng = marker.getPosition(); | |
Point startPoint = proj.toScreenLocation(markerLatLng); | |
startPoint.offset(0, -10); | |
final LatLng startLatLng = proj.fromScreenLocation(startPoint); | |
final Interpolator interpolator = new BounceInterpolator(); | |
handler.post(new Runnable() { | |
@Override | |
public void run() { | |
long elapsed = SystemClock.uptimeMillis() - startTime; | |
float t = interpolator.getInterpolation((float) elapsed / duration); | |
double lng = t * markerLatLng.longitude + (1 - t) * startLatLng.longitude; | |
double lat = t * markerLatLng.latitude + (1 - t) * startLatLng.latitude; | |
marker.setPosition(new LatLng(lat, lng)); | |
if (t < 1.0) { | |
// Post again 16ms later (60fps) | |
handler.postDelayed(this, 16); | |
} | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment