我正在使用 google maps api v3 开发一个项目,并且正在尝试制作它,以便在单击标记时出现一个信息窗口。我已经完成了这一点,但现在我想要的是当点击不同的标记时显示不同的内容,我似乎无法弄清楚。任何帮助表示赞赏。谢谢!
function initialize() {
var locations = [
['Phi Delta Theta', 39.511747,-84.735117],
['Pi Kappa Alpha', 39.511776, -84.735684],
['Sigma Nu', 39.513921, -84.735159],
['Sigma Alpha Epsilon', 39.514332, -84.734956],
['Beta Theta Pi', 39.5107519, -84.738549]
];
var myLatlng = new google.maps.LatLng(39.511747,-84.735117);
var mapOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var contentString = '<div id="content">'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}