我无法使我的标记显示不同的信息窗口。标记始终会显示最后一个 "contentString" 的内容。
我已经阅读了几篇其他帖子,但它们似乎都没有帮助。
这是代码:
我已经阅读了几篇其他帖子,但它们似乎都没有帮助。
这是代码:
function setMarkers(branches, map) {
var bounds = new google.maps.LatLngBounds();
var contentString = null;
var infowindow = null;
infowindow = new google.maps.InfoWindow();
for (var i = 0; i < branches.length; i++) {
var marker = null;
branch = branches[i];
var myLatlngMarker = new google.maps.LatLng(branch[0], branch[1]);
contentString = '<p>' + branch[3] + '</p>';
var marker = new google.maps.Marker({
position: myLatlngMarker,
map: map,
title: branch[2]
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(contentString);
infowindow.open(map, this);
});
bounds.extend(myLatlngMarker);
}
map.fitBounds(bounds);
}
有人能看出我哪里做错了吗?
谢谢