我在我的網站上使用Google地圖,它工作正常。但是如果我使用自己的標記圖像,那麼信息窗口不會再彈出。任何人的想法爲什麼?Google Maps API信息窗口不會打開
您可以在
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 6,
center: {lat: 50.984768, lng: 11.029880}
});
setMarkers(map);
}
var musters = <?php echo json_encode($musters); ?>;
function setMarkers(map) {
var image = {
url: 'img/markerBlue.png'
};
for (var i = 0; i < musters.length; i++) {
var muster = musters[i];
var infowindow = new google.maps.InfoWindow(); /* SINGLE */
var markers = new google.maps.Marker({
position: {lat: muster[1], lng: muster[2]},
map: map,
icon: image,
title: muster[0]
});
placeMarker(muster);
function placeMarker(loc) {
var latLng = new google.maps.LatLng(loc[1], loc[2]);
var marker = new google.maps.Marker({
position : latLng,
map : map
});
google.maps.event.addListener(marker, 'click', function(){
infowindow.close(); // Close previously opened infowindow
infowindow.setContent("<div id='infowindow'>"+ loc[3] +"</div>");
infowindow.open(map, marker);
});
}
}
}