这可能是一个简单得可笑的问题。
我正在尝试显示地图,其中标记信息窗口将显示以下内容:
名称
地址
关于(即描述)
URL
使用 PHP 从 mySQL 数据库中查询标记。该代码当前正确映射所有标记,但仅在信息窗口中显示“名称”属性。添加其他 3 个属性所需的缺失代码是什么?(地址、关于、URL?)我的猜测是代码中此时需要调整一些内容:
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i].getAttribute("name"));
infowindow.open(map, marker);
}
})(marker, i));
如果可能,请用必要的脚本回答!
- 数据库输出的实时链接:http
://www.oaktonjapan.com/testmap/testcode3.php
**请注意,第一个(PAX Coworking)和最后一个(Venture Generation)填充了“地址、关于和 URL 内容。
- 现有输出的实时链接:http: //oaktonjapan.com/testmap/testmap5.html
* *单击红色相扑摔跤手标记。如果编码正确,该标记应显示所有 4 个属性...
当前代码:
function load() {
var cluster = [];
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(35.681382,139.766084),
zoom: 14,
mapTypeId: 'roadmap'
});
var infowindow = new google.maps.InfoWindow();
var min = .999999;
var max = 1.000001;
// Change this depending on the name of your PHP file
downloadUrl("testcode3.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 about = markers[i].getAttribute("about");
var url = markers[i].getAttribute("url");
var offsetLat = markers[i].getAttribute("lat") * (Math.random() * (max - min) + min);
var offsetLng = markers[i].getAttribute("lng") * (Math.random() * (max - min) + min);
var point = new google.maps.LatLng(offsetLat, offsetLng);
var html = "<b>" + name + "</b> <br/>" + address;
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
content: html
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i].getAttribute("name"));
infowindow.open(map, marker);
}
})(marker, i));
cluster.push(marker);
}
var mc = new MarkerClusterer(map,cluster);
});
}
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, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
function doNothing() {}
提前感谢您的帮助!