Closing any open info windows in google maps api v3

后端 未结 6 1443
旧时难觅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:19

    It should be sufficient to have a global infowindow and then to change the position and content of that infowindow.

    var infowindow = new google.maps.InfoWindow();
    
    // Call this function to open an infowindow i.e. on click.
    function respondToClick(latlng) {
      infowindow.setOptions({
        position: latlng,
        content" "Hello, world"
      });
    }
    

    As the same infowindow is used each time, you are guarantee'd to only ever have one open, and it uses less resources / memory than creating and then destroying multiple infowindows.

提交回复
热议问题