好的,我一直在尝试在填充了许多标记的地图上实现Infobubbles with tabs,从具有ajax调用的Mysql数据库中恢复(使用this tutorial from Google构建)。
点击事件对每个标记反应良好,但问题是每个信息块都在选项卡中显示相同的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);
});
}
答案 0 :(得分:0)
因为您的infoWindow只创建一次,并且只在代码执行开始时创建。您需要将infoWindow的初始化放在click事件中,或者使用setContent方法修改单击标记上的内容