好的,我一直在尝试使用填充了许多标记的地图上的选项卡来实现 Infobubbles,这些标记通过 ajax 调用从 Mysql 数据库中恢复(使用Google 的本教程构建)。
click 事件对每个标记都反应良好,但问题是每个 infobubble 都在选项卡中显示相同的 html 内容,我猜从添加的最后一个标记开始......肯定有一个关闭问题,但我觉得很没用此刻,这让我快疯了!感谢您提供任何帮助...
function init() {
var mapCenter = new google.maps.LatLng(48.204612, 7.419058);
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 9,
center: mapCenter,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infoBubble = new InfoBubble({
map: map,
maxWidth: 300,
disableAnimation: true
});
// Get markers and info from the database
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 description = markers[i].getAttribute("description");
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,
title: name,
position: point,
icon: icon.icon,
shadow: icon.shadow,
});
google.maps.event.addListener(marker, 'click', function() {
if (!infoBubble.isOpen()) {
infoBubble.open(map, this);
}
});
google.maps.event.addListener(map, "click", function(){
infoBubble.close();
});
}
infoBubble.addTab('Tab1', html);
infoBubble.addTab('Tab2', description);
});
}