Google Maps: Auto close open InfoWindows?

前端 未结 12 713
终归单人心
终归单人心 2020-12-02 05:30

On my site, I\'m using Google Maps API v3 to place house markers on the map.

The InfoWindows stay open unless you explicitly click the close icon. Meaning, you can h

12条回答
  •  不知归路
    2020-12-02 06:22

    var map;
    var infowindow;
    ...
    function createMarker(...) {
        var marker = new google.maps.Marker({...});
        google.maps.event.addListener(marker, 'click', function() {
            ...
            if (infowindow) {
                infowindow.close();
            };
            infowindow = new google.maps.InfoWindow({
                content: contentString,
                maxWidth: 300
            });
            infowindow.open(map, marker);
        }
    ...
    function initialize() {
        ...
        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        ...
        google.maps.event.addListener(map, 'click', function(event) {
            if (infowindow) {
                infowindow.close();
            };
            ...
        }
    }
    

提交回复
热议问题