I am doing a google map which will read a set of coordinates and put the marker on the map one by one.
Below is my idea:
function A{
for loop(
set marker
call setTimeout('A',2seconds)
)
}
my idea is to set a marker and use setTimeout to wait 2 seconds and then set the next marker.
However, it doesn’t work. it show all the markers at the same time and repeat to renew all markers.
How can i achieve my goal?
Thanks for your help!!!!!!!!!!!!!!!
Here is my code:
function marker(){
var marker;
var i=0;
while(i<locations.length){
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
animation: google.maps.Animation.DROP,
map: map
});
i=i+1;
var t=setTimeout("marker()",2000);
}
}
marker();
You need to return after setting the first marker. You also need a parameter to A which specifies which marker to show.