我已经编写了以下代码来在谷歌地图中显示多个标记,并且我成功了。现在我想将放置动画应用于标记,并希望在特定时间间隔后放置标记。我知道我想调用setTimeout
方法,但是不知道在哪里调用这个方法来达到效果
<script type="text/javascript">
window.onload=function(){
if(markers.length>0){
var mapOptions={
center:new google.maps.LatLng(markers[0].lat,markers[0].lng),
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var infoWindow=new google.maps.InfoWindow();
var map=new google.maps.Map(document.getElementById("dvMap"),mapOptions);
var bounds=new google.maps.LatLngBounds();
for(i=0;i<markers.length;i++){
var imageIcon=i+1;
var data=markers[i];
var latlng=new google.maps.LatLng(data.lat,data.lng);
var marker=new google.maps.Marker({
position:latlng,
map:map,
title:data.title,
icon:"Icon/marker"+imageIcon+".PNG",
animation:google.maps.Animation.DROP
});
bounds.extend(marker.getPosition());
(function(marker,data){
google.maps.event.addListener(marker,"click",function(e){
infoWindow.setContent(data.description);
infoWindow.open(map,marker);
if(marker.getAnimation()!=null){
marker.setAnimation(null);
}else{
marker.setAnimation(google.maps.Animation.BOUNCE);
}
});
})(marker,data);
} //for loop ends here
map.fitBounds(bounds);
map.setCenter(bounds.getCenter());
}//if condition check for marker.length ends here
} //windows.load function ends here
</script>