[英]How to automatic display info window on Google maps?
我目前在我的網站上有一個google map,每個信息窗口都有一個“ click”事件。 因此,如果您單擊一個標記,則會彈出信息窗口。 但是,我希望infowindow能夠自動顯示,而不必先點擊它們。
這是我的代碼,有人可以幫我嗎?
var map = new google.maps.Map(document.getElementById('map'), {
// Maps zoom level 16
zoom: 16,
// Start location
center: new google.maps.LatLng(51.996098, 5.891174),
// Map style
mapTypeId: google.maps.MapTypeId.HYBRID
});
// info window
var infowindow = new google.maps.InfoWindow();
var marker, i;
// Markers
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));
}
function clickroute(lati, long) {
var latLng = new google.maps.LatLng(lati, long);
map.panTo(latLng);
}
</script>
每次創建標記時,還要創建一個信息窗口並將其打開:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
var infoWindow = new google.maps.InfoWindow();
infoWindow.setContent(locations[i][0]);
infoWindow.open(map, marker);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.