Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Map v2 Marker Animation

Do anyone have idea how this animation's implementation is possible in google map api v2. Check out this here. I would like to know how this is done. Please let me know if anyone have any sample code regarding this.

Thanks in advance.

like image 597
GrIsHu Avatar asked Dec 20 '12 12:12

GrIsHu


People also ask

How do I change a marker on Google Maps?

To edit the marker color, click or tap on the marker icon. When you do that, you can change both the color of the marker and its style. Go for the color or style you want to change and then click OK to see the effect. Click on the button labeled Done to save your new marker color settings.


2 Answers

I found a solution that worked for me:

final LatLng target = NEW_LOCATION;

final long duration = 400;
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = map.getProjection();

Point startPoint = proj.toScreenLocation(marker.getPosition());
final LatLng startLatLng = proj.fromScreenLocation(startPoint);

final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
    @Override
    public void run() {
        long elapsed = SystemClock.uptimeMillis() - start;
        if (elapsed > duration) {
            elapsed = duration;
        }
        float t = interpolator.getInterpolation((float) elapsed / duration);
        double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
        double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
        marker.setPosition(new LatLng(lat, lng));
        if (t < 1.0) {
            // Post again 10ms later.
            handler.postDelayed(this, 10);
        } else {
            // animation ended
        }
    }
});
like image 120
D-32 Avatar answered Oct 14 '22 01:10

D-32


You are welcome to change the position of a Marker at any point by calling setPosition(). You are welcome to change the position of the "camera" (i.e., the map's center and zoom level) at any point by applying a CameraUpdate object using moveTo() or animateTo() on GoogleMap. Combining these with a light timing loop (e.g., using postDelayed()) should allow you to achieve a similar animation effect.

like image 7
CommonsWare Avatar answered Oct 14 '22 03:10

CommonsWare