Google Maps: Auto close open InfoWindows?

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

    My solution.

    var map;
    var infowindow = new google.maps.InfoWindow();
    ...
    function createMarker(...) {
    var marker = new google.maps.Marker({
         ...,
         descrip: infowindowHtmlContent  
    });
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setOptions({
            content: this.descrip,
            maxWidth:300
        });
        infowindow.open(map, marker);
    });
    

提交回复
热议问题