Closing any open info windows in google maps api v3

后端 未结 6 1432
旧时难觅i
旧时难觅i 2021-01-31 03:25

As the title states, on a given event (for me this happens to be upon opening a new google.maps.InfoWindow I want to be able to close any other currently open info

6条回答
  •  孤独总比滥情好
    2021-01-31 04:25

    I ran into the same problem and fixed it by creating a global info window.

    var infowindow = new google.maps.InfoWindow();
    

    Then I have a function to do the following on the click listener:

    function getInfoWindowEvent(marker) {
        infowindow.close()
        infowindow.setContent("This is where my HTML content goes.");
        infowindow.open(map, marker);
    }
    

    This achieves what I think you're looking for b/c there is now only one info window on the map and I just close it, reload the content and open it again for the given marker.

提交回复
热议问题