Я пытаюсь сбрасывать маркеры один за другим, а не бросать их все одновременно. Мой drop function()
, похоже, не работает здесь. Я не знаю, что не так. Пожалуйста, взгляните на мой код.Google Maps marker DROP
<script>
function initialize() {
var myLatlng = new google.maps.LatLng(63.417622, 10.404316);
var mapOptions = {
zoom: 13,
center: myLatlng
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var marker;
var locations = [];
locations.push ({name: "1", p: new google.maps.LatLng(63.417622, 10.404316)});
locations.push ({name: "2", p: new google.maps.LatLng(63.409868, 10.446512)});
locations.push ({name: "3", p: new google.maps.LatLng(63.429070, 10.390894)});
locations.push ({name: "4", p: new google.maps.LatLng(63.437208,10.452692)});
function addMarker(){
for (var i = 0; i < locations.length; i++){
marker = new google.maps.Marker({position: locations[i].p, map: map, title: locations[i].name, icon: 'cabin_icon.png', animation: google.maps.Animation.DROP});
}
} //This put my markers on the map all at once.
//Function to drop them at one after another after a few milliseconds.
function drop(){
for (var j = 0; j < locations.length; j++) {
setTimeout(function(){
addMarker();
}, j * 200);
};
}; //But this function is not working. Markers are not even showing up after I have created this function.
}
google.maps.event.addDomListener(window, 'load', initialize); </script>
Я попытался отредактировать код разными способами, но не смог понять это правильно. Я тоже пробовал с Google tutorial on this, и мне тоже не повезло с кодом. Поэтому мне нужна твоя помощь.