i´ve made a tutorial from google maps api to load markers from database and php with a generated xml file to the map. Now i am trying to add a delay with setTimeout or so to drop one marker after another like this example. I very beginner and would very happy if someone can tell me how to do this!
downloadUrl("php/addLocations.php", function (data) {
var xml = parseXml(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var address = markers[i].getAttribute("address");
var type = markers[i].getAttribute("type");
var profile_image = markers[i].getAttribute("myimage");
var point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address + "<br/>" + "<img src='uploads/" + profile_image + "' width='100px' />";
var icon = customIcons[type] || {};
var marker2 = new google.maps.Marker({
map: bigmap,
position: point,
icon: icon.icon,
animation: google.maps.Animation.DROP,
shadow: icon.shadow
});
bindInfoWindow(marker2, bigmap, infoWindowLoc, html);
}
});
var infoWindowLoc = new google.maps.InfoWindow;
function bindInfoWindow(marker2, bigmap, infoWindowLoc, html) {
google.maps.event.addListener(marker2, 'click', function () {
//openMarkerBox();
// panning map
bigmap.panTo(marker2.position);
infoWindowLoc.setContent(html);
infoWindowLoc.open(bigmap, marker2);
});
}
function downloadUrl(url, callback) {
var request = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest;
request.onreadystatechange = function () {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function parseXml(str) {
if (window.ActiveXObject) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
} else if (window.DOMParser) {
return (new DOMParser).parseFromString(str, 'text/xml');
}
}
function doNothing() {
alert("shit")
}
Well, if you inspect the code at your example, everything you need is there. Take a look at:
1 – The
onclickhandler that is attached to the Drop Markers button:Online documentation for
onclickis available: at this link.2 – The
drop()function from your example:Online documentation for the
setTimeoutfunction is available: at this link.3 – The
addMarker()function from your example:Online documentation for
google.maps.markeranimation is available: at this link.Walk through the code, dig in a little, and you should be able to figure this out.