您好我已经根据自己的示例和其他网站调整了代码,我需要信息窗口显示四个属性,“名称”,“地址”,“电话”和“品种”。删除var type = markers[i].getAttribute("type");
后(这是Google地图示例代码中的现有属性)
并将其替换为:
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);
}
});
}
干杯!
答案 0 :(得分:2)
这看起来像问题:
var icon = customIcons[type] || {};
您复制的代码设置为根据“类型”更改图标。如果删除该行:
var type = markers[i].getAttribute("type");
应该有一个明确的javascript错误。如果您不想要自定义图标,请将该行更改为var icon = {};或删除它并将您的标记更改为:
var marker = new google.maps.Marker({
map: map,
position: point
});