1
我有一个安装程序,其中存在多个标记,每个标记在点击时加载到单个InfoWindow。Google Maps API v3 - 当点击标记时点击事件不会触发另一个InfoWindow打开时
不幸的是,在另一个窗口打开时,标记的点击事件似乎没有被点击。
这似乎是一种奇怪的行为。有没有其他人发现这种情况?
感谢
我下面的代码:
var infoWindow = new google.maps.InfoWindow();
if(markers) {
var length = markers.length;
for(var i = 0; i < length; i++) {
var details = markers[i];
markers[i] = new google.maps.Marker({
title: details.name,
position: new google.maps.LatLng(details.location[0],details.location[1]),
locCode: details.locCode
});
markers[i].setMap(map);
var thisMarker = markers[i];
google.maps.event.addListener(thisMarker, 'click', (function(thisMarker, i, details) {
// self calling function was the key to get this to work
return function() {
$.ajax({
url: 'js/locations/'+details.locCode+'.js',
dataType: 'script',
success: function(data) {
// do my specific stuff here, basically adding html to the info-window div via jQuery
// set the content, and open the info window
infoWindow.setContent($("#info-window").html());
infoWindow.open(map, thisMarker);
}
});
}
})(thisMarker, i, details));
}
}
感谢鲍勃。尽管如此,我还是从ajax调用回来了内容。我已经尝试了一系列infoWindows,没有运气。这是你推荐的关键部分吗? – evanmcd
好的,实际上帮助修复的部分是每次创建htmlContent,而不是操纵现有元素。示例:https://gist.github.com/1099679 – evanmcd