嗨,我已经修改了示例和其他网站的代码以适合自己,我需要信息窗口显示四个属性,“姓名”“地址”“电话”和“品种”。一旦我删除var type = markers[i].getAttribute("type");
(这是谷歌地图示例代码中的现有属性)
并将其替换为:
var phone = markers[i].getAttribute("phone");
var breeds = markers[i].getAttribute("breeds");
地图不显示任何标记。我对javascript没有那么高,所以它可能是我缺少的一些简单的东西。该地图可在此处找到:http ://connormccarra.com/test/ 。
信息取自此 xml 文件:http ://connormccarra.com/test/phpsqlajax_genxml3.php
function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(53.5076512854544, -7.701416015625),
zoom: 7,
mapTypeId: 'roadmap'
});
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("phpsqlajax_genxml3.php", function(data) {
var xml = data.responseXML;
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 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);
}
});
}
干杯!