Google Maps: Auto close open InfoWindows?

前端 未结 12 709
终归单人心
终归单人心 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:30

    alternative solution for this with using many infowindows: save prev opened infowindow in a variable and then close it when new window opened

    var prev_infowindow =false; 
    ...
    base.attachInfo = function(marker, i){
        var infowindow = new google.maps.InfoWindow({
            content: 'yourmarkerinfocontent'
        });
    
        google.maps.event.addListener(marker, 'click', function(){
            if( prev_infowindow ) {
               prev_infowindow.close();
            }
    
            prev_infowindow = infowindow;
            infowindow.open(base.map, marker);
        });
    }
    

提交回复
热议问题