有没有人可以帮我在我的eventListener中编写代码,这样infowindow就会执行以下操作:如果当前处于关闭状态,则打开;如果当前处于打开状态,则关闭。
我尝试了以下几种方法,但都没有成功。
google.maps.event.addListener(marker, 'click', function() {
if(infowindow.closed == true){
infowindow.open(map, marker)
}
else{
infowindow.close(map, marker)
}
})发布于 2014-02-14 15:39:29
您可以使用类似以下内容:
infoWindowClosed = true;
google.maps.event.addListener(marker, 'click', function() {
if (infoWindowClosed) {
infowindow.open(map, marker);
infoWindowClosed = false;
} else {
infowindow.close(map, marker)
infoWindowClosed = true;
}
})发布于 2014-02-14 15:26:09
var currentInfoWindow = null;
then on every marker click event I do something like this:
var infowindow = new google.maps.InfoWindow({
content: "your content here"
});
google.maps.event.addListener(marker, 'click', function() {
if (currentInfoWindow != null) {
currentInfoWindow.close();
}
infowindow.open(map, marker);
currentInfoWindow = infowindow;
}); 来源:https://groups.google.com/forum/#!topic/google-maps-js-api-v3/cA2VRg4TO1k
发布于 2014-02-14 15:48:20
先尝试关闭infow窗口,然后单击以再次打开:
<script>
var onMarkerClick = function() {
var marker = this;
var latLng = marker.getPosition();
infoWindow.setContent('<h3>Marker position is:</h3>' +
latLng.lat() + ', ' + latLng.lng());
infoWindow.open(map, marker);
};
google.maps.event.addListener(map, 'click', function() {
infoWindow.close();
});
var marker1 = new google.maps.Marker({
map: map,
position: new google.maps.LatLng(37.789879, -122.390442)
});
google.maps.event.addListener(marker1, 'click', onMarkerClick);
</script>有关更多信息,请访问此url的源代码:
https://stackoverflow.com/questions/21772959
复制相似问题