I need to have only one InfoWindow open on my Google Map. I need to close all other InfoWindows before I open a new one.
Can someone show me how to do this?
You can modify the whole InfoWindow using jquery alone... var popup = new google. maps. InfoWindow({ content:'<p id="hook">Hello World!
Calling InfoWindow. getOpenedState() returns a boolean which reflects the state (opened/closed) of the infowindow.
When you create an info window, it is not displayed automatically on the map. To make the info window visible, you must call the open() method on the InfoWindow , passing an InfoWindowOpenOptions object literal specifying the following options: map specifies the map or Street View panorama on which to open.
You need to create just one InfoWindow
object, keep a reference to it, and reuse if for all the markers. Quoting from the Google Maps API Docs:
If you only want one info window to display at a time (as is the behavior on Google Maps), you need only create one info window, which you can reassign to different locations or markers upon map events (such as user clicks).
Therefore, you may simply want to create the InfoWindow
object just after you initialize your map, and then handle the click
event handlers of your markers as follows. Let's say you have a marker called someMarker
:
google.maps.event.addListener(someMarker, 'click', function() { infowindow.setContent('Hello World'); infowindow.open(map, this); });
Then the InfoWindow
should automatically close when you click on a new marker without having to call the close()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With