I've been looking for a good solution to animate a marker using the Google Maps JavaScript API V3. The marker will be animated on a predetermined path defined using latitude and longitude coordinates.
For all the research I've done, I still can't find a solution that is compatible with version 3 of the JavaScript Google Maps API. Looking at this earlier StackOverflow post, apparently it was possible to animate using Version 2 of the API, using GRoute
and setting the position of a marker to points along the route using a timer.
Here is the code that was previously suggested. I understand how it works logically, but I have no idea how this could be ported to work with version 3 of the Google Maps API:
function moveToStep(yourmarker,yourroute,c) {
if {yourroute.getNumSteps() > c) {
yourmarker.setLatLng(yourroute.getStep(c).getLatLng());
window.setTimeout(function(){
moveToStep(yourmarker,yourroute,c+1);
},500);
}
}
moveToStep(marker,route,0);
There is no mention of GRoute
, getNumSteps
(which I'm supposing returns the number of coordinates defined on a given route, setLatLng
(I believe which gets the latitude and longitude coordinates of the marker), or moveToStep
(which actually moves the marker) in the version 3 full documentation and reference.
It seems that Google has completely rewritten the API from version 2 to version 3, as these functions (which seem to be pretty basic) all have either been removed or renamed (I'm not sure which.)
The only mention of animations I have ever seen in version 3 of the JavaScript API has been for animating the markers when they first appear on the map, by making them either BOUNCE
or DROP
. However, these do not actually move the latitude/longitude coordinates of the marker, merely the manner in which they are placed on the map. These two marker animations are mentioned in the API reference here.
On the same aforementioned StackOverflow post, a link was provided to a working example of marker animation using the JavaScript API. However, as a commenter pointed out, the animation was done using an earlier version of the library (available here.)
Ultimately, I guess I have two questions:
1: Is it possible to animate markers along a given path using the Google Maps V3 API?
and if not, then
2: Will I be forced to use a deprecated library to achieve this, or are there any other known solutions?
Thank you very much for any contribution that may help solve this problem!