Close all infowindows in Google Maps API v3

前端 未结 11 1226
小蘑菇
小蘑菇 2020-12-08 00:01

I am busy with a script that will make a google maps canvas on my website, with multiple markers. I want that when you click on a marker, a infowindow opens. I have done tha

11条回答
  •  半阙折子戏
    2020-12-08 00:36

    When dealing with marker clusters this one worked for me.

    var infowindow = null;
    
    google.maps.event.addListener(marker, "click", function () {
    
            if (infowindow) {
                infowindow.close();
            }
            var markerMap = this.getMap();
            infowindow = this.info;
            this.info.open(markerMap, this);
    
    
        });
    

提交回复
热议问题