我很难使用 Google Maps V3 API 显示我的标记。
加载页面时出现以下错误 -
类型错误:xml 未定义
var 标记 = xml.documentElement.getElementsByTagName("marker");
我尝试以几种不同的方式声明 xml 变量,但无济于事。
非常感谢任何帮助。
function load() {
map = new google.maps.Map(document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.765558,-122.450867),
zoom: 11,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsearch.php", function(data) {
xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");//<- error occurs right here
//Uncaught TypeError: Cannot read property 'documentElement' of undefined
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 point = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
});
bindInfoWindow(marker, map, infoWindow, html);
}
});
}
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);
}
页面在这里:
http://www.students.bl.rdi.co.uk/stu26984/index2.php
似乎对以下问题的修复应该有所帮助,但我不明白为什么我仍然被告知变量未定义。