我已经从谷歌地图 api制作了一个教程,以将生成的 xml 文件从数据库和 php 中加载到地图中。现在我正在尝试使用 setTimeout 左右添加一个延迟,以像这个示例一样一个接一个地放置一个标记。我非常初学者,如果有人能告诉我如何做到这一点,我会非常高兴!
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")
}