Maps 地图加载时如何默认打开所有信息窗口?
我一直在尝试在第一次加载地图时打开marker的所有信息窗口。但是,“infoWindow.open(map,marker[i]);”或其他一些变体不起作用。甚至我也尝试了另一个for循环,但没有成功。你有什么建议吗Maps 地图加载时如何默认打开所有信息窗口?,maps,marker,infowindow,Maps,Marker,Infowindow,我一直在尝试在第一次加载地图时打开marker的所有信息窗口。但是,“infoWindow.open(map,marker[i]);”或其他一些变体不起作用。甚至我也尝试了另一个for循环,但没有成功。你有什么建议吗 var spLocations_length = spLocations.length; // Display multiple markers on a map var infoWindow = new google.maps.InfoWindow(), marker,
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);
}
var spLocations\u length=spLocations.length;
//在地图上显示多个标记
var infoWindow=new google.maps.infoWindow(),
马克,我;
var-iconCounter=0;
//在我们的标记阵列中循环并将每个标记放置在地图上
对于(i=0;i
最后我找到了一个解决方案,但这是间接的方法
相反,打开所有信息窗口时,我使用了“标记标签”解决方案
诀窍是使用“标记图标”图像作为背景,而不是信息窗口容器。
因此,标签文本通过for循环和数组进行动态更改
我希望这个片段能帮助别人
// locations Array contains location coords and titles //
var locations[.....];
for (i = 0; i < locations.lenght; i++) {
var position = new google.maps.LatLng(locations[i][1], locations[i][2]);
marker = new google.maps.Marker({
position: position,
map: map,
title: locations[i][0],
icon: "https.......",
index: i,
label: {
text: locations.length + locations[i][0] "This is text",
color: 'black',
fontSize: "14px",
fontFamily: "Roboto, Arial, sans-serif",
fontWeight: "bold"
}
});
}
//位置数组包含位置坐标和标题//
风险值位置[…];
对于(i=0;i
谷歌资料来源: