【发布时间】:2017-12-23 03:17:59
【问题描述】:
一开始加载地图时,我一直在尝试打开所有标记的 infoWindows。然而“infoWindow.open(map, marker[i]);”或其他一些变化不起作用。即使我在其中尝试了另一个 for 循环,但无法做到。那你有什么建议吗?
var spLocations_length = spLocations.length;
// Display multiple markers on a map
var infoWindow = new google.maps.InfoWindow(),
marker, i;
var iconCounter = 0;
// Loop through our array of markers & place each one on the map
for (i = 0; i < spLocations_length; i++) {
var position = new google.maps.LatLng(spLocations[i][1], spLocations[i][2]);
bounds.extend(position);
marker = new google.maps.Marker({
position: position,
map: map,
title: spLocations[i][0],
icon: icons[iconCounter]
});
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infoWindow.setContent(infoWindowContent[i][0]);
infoWindow.open(map, marker);
}
})(marker, i));
// IT DOESN'T WORK FOR OPEN ALL MARKERS INFOWINDOWS WHEN MAP LOADED
infoWindow.open(map, marker[i]);
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
}
【问题讨论】:
标签: maps marker infowindow