V3 How to close all infowindows before opening another one?

14,063 views
Skip to first unread message

Noviceguy

unread,
Sep 15, 2009, 9:42:21 AM9/15/09
to Google Maps JavaScript API v3
Hi,

i am using api v3 for googlemaps and i have an issue,

i have an event that attaches an infowindow to every marker on click.

the problem is that if the user click on a marker, and forgets to
close the infowindow, and then clicks on another marker.

we have two infowindow that appears

Is there a method that closes all overlays on the map?

Pete

unread,
Sep 15, 2009, 9:45:50 AM9/15/09
to Google Maps JavaScript API v3
You need to use something similar to this:
http://www.lootogo.com/googlemapsapi3/markerPlugin.html

only of course, only clear info windows, not markers.

Thanks
-Pete

Esa

unread,
Sep 16, 2009, 1:26:18 PM9/16/09
to Google Maps JavaScript API v3


On Sep 15, 4:42 pm, Noviceguy wrote:

> i have an event that attaches an infowindow to every marker on click.
>

Another approach is to create a single InfoWindow object and change
its contents and position. There is a custom method
marker.attachInfoWindow() presented here
http://koti.mbnet.fi/ojalesa/boundsbox/attachinfowindow.htm

That creates the InfoWindow object and recycles it. InfoWindow is also
closed by click on map.

Petr Peller

unread,
Oct 7, 2009, 5:08:22 AM10/7/09
to Google Maps JavaScript API v3
Hi,

I think the most easiest way is to hold opened (active) infoWindow in
a variable so you can access it's .close() method in click event of
each marker.

======================================
Example (it's incomplete sample, but I think you can see the idea)

//Create new window
iWindow = new google.maps.InfoWindow();

google.maps.event.addListener(marker, 'click', function()
{
//Close active window if exists
if(activeWindow != null) activeWindow.close();

//Open new window
iWindow.open(map, marker);

//Store new window in global variable
activeWindow = iWindow;
});
Reply all
Reply to author
Forward
0 new messages