Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bounce a pin in google maps once

I want to bounce a pin on a google map once. The following code will make the marker bounce but it just keeps going...

myPin.setAnimation(google.maps.Animation.BOUNCE); 

Then calling

myPin.setAnimation(null); 

makes the animation stop. Setting a timeout works but the duration of a bounce doesn't look like it is a round number so doing this

  setTimeout(function(){ myPin.setAnimation(null); }, 1000); 

Make the bounce animation end prematurely and look terrible.

Does anyone know of a better way to accomplish this?

like image 505
Patrick Arlt Avatar asked Sep 07 '11 19:09

Patrick Arlt


People also ask

How do you move a marker smoothly?

There is a method makeMarker() you just need to call from onMapReady() method . There is two method rotateMarker() and moveVechile() to rotate and move marker. Hope this will help you.


2 Answers

Bit of a simple approach: Google's bounce animation appears to take exactly 750 ms for one cycle. Thus, simply set the timeout to 750 ms and the animation will stop exactly at the end of the first bounce. Works for me on FF 7, Chrome 14 and IE 8:

    marker.setAnimation(google.maps.Animation.BOUNCE);     setTimeout(function(){ marker.setAnimation(null); }, 750); 
like image 137
Simon Steinberger Avatar answered Sep 28 '22 07:09

Simon Steinberger


At the moment there is no built in animation for bouncing once.

If you are OK with it bouncing twice then i strongly suggest that you use this:

marker.setAnimation(4);

like image 20
Mikael Avatar answered Sep 28 '22 08:09

Mikael