This is Part 6 of a week long series featuring code for the Google Maps API.
The theme for today is Animation (per the request of Ralph). For programmers who want to make a walkthrough of their town, or a tutorial – play-by-play animation is an important feature to have – and one that is missing from the default API.
I’ve added the functionality to the API such that you can animate the user’s map view based upon:
- An array of points.
- An array of markers.
- An array of markers and points.
- A Polyline.
In addition to this, if you wish to use markers in your animation – and if you’ve bound a function to the “click” event of the marker – then that click will be triggered, displaying an info window (for example).
Using all of these features together, in tandem, you can create a pretty convincing slideshow. To see a demo of the animation at work, click here.
To interface with this, here is the function that you need to call:
map.animate( points, closeFunction, pointWait, markerWait );
points – is a GPolyline or an Array of GMarkers and/or GPoints.
closeFunction (optional) – this function will be called whenever the animation has been completed.
pointWait – this is the amount of time to wait at a point (or a marker without a ‘click’ event). The default is 3000 milliseconds.
markerWait – if you’ve bound a function to the click event of a marker then this is how long you wish to wait (for example, if you want to give a user time to read an Info Window). The default is 6000 milliseconds.
To use the above code, simply include this file in the header of your code – after you’ve included your Google Map API file – and you should be ready to go! Happy animating!
Ralph Whitbeck (August 18, 2005 at 8:37 am)
Sweet! #2 following points and markers is exactly what I am trying to do. I’ll post my results when i am done…probably this weekend.
Thanks man.
The Map Room (September 18, 2005 at 8:57 pm)
Coding the Google Maps API
About a month ago, our friend John Resig spent a week on Google Maps: “I’ve been working a number of contract jobs — all of which have centered around the usage of the Google Maps API, a powerful tool for…
ST (April 26, 2006 at 7:44 pm)
Is there a way to get this to automatically follow all markers without having to duplicate the coordinates?
yao (July 10, 2006 at 10:53 pm)
it seems that this code won’t work for IE.
Addy (October 17, 2006 at 5:13 am)
Hi,
It looks very nice, but I didnot get it to work with IE as well.
Is this because google maps has a new api version or is this because IE doesnot work with this code?
If it is the first could you please update the code?
Thanks