Auto close InfoWindow when another marker is pressed, or they move?

10,936 views
Skip to first unread message

Andy Newby

unread,
Jun 18, 2011, 11:02:59 AM6/18/11
to google-map...@googlegroups.com
Hi,

I've almost finished converting our map from the v2 API to v3:

http://www.chambresdhotesfrancedev.com/Europe/

I have 1 last thing I need to do, which I can't seem to work out. When you click on an info window at the moment, it will stay open when you move the map (and when an InfoWindow is open and you move the map around, it will auto-center again on that marker)

Is there a way to make it so the window is auto-closed when you move the map?

TIA

Andy

geoco...@gmail.com

unread,
Jun 18, 2011, 11:24:49 AM6/18/11
to Google Maps JavaScript API v3
On Jun 18, 8:02 am, Andy Newby <andy.ne...@gmail.com> wrote:
> Hi,
>
> I've almost finished converting our map from the v2 API to v3:
>
> http://www.chambresdhotesfrancedev.com/Europe/
>
> I have 1 last thing I need to do, which I can't seem to work out. When you
> click on an info window at the moment, it will stay open when you move the
> map (and when an InfoWindow is open and you move the map around, it will
> auto-center again on that marker)

I don't see that behavior in Chrome.

>
> Is there a way to make it so the window is auto-closed when you move the
> map?

You can write code to close it on the center_changed or bounds_changed
events.

-- Larry

>
> TIA
>
> Andy

Andy Newby

unread,
Jun 19, 2011, 6:55:31 AM6/19/11
to google-map...@googlegroups.com
Thanks, will give that a go :)


>
> TIA
>
> Andy

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.




--
Andy Newby
an...@ultranerds.com

Gary B

unread,
Jun 20, 2011, 10:27:38 AM6/20/11
to Google Maps JavaScript API v3
I've done something similar to keep just one infoWindow open.
I initialize a var like this
var currentInfoWindow = null;

then on every marker click event I do something like this:

var infowindow = new google.maps.InfoWindow({
content: "your content here"
});
google.maps.event.addListener(marker, 'click', function() {
if (currentInfoWindow != null) {
currentInfoWindow.close();
}
infowindow.open(map, marker);
currentInfoWindow = infowindow;
});

On Jun 18, 11:24 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:

Mike Saeger

unread,
Apr 2, 2018, 7:43:05 PM4/2/18
to Google Maps JavaScript API v3
I've looked all over the net and this solution was the easiest for me to implement -- AND IT WORKED! Thanks!

rahul mishra

unread,
Apr 18, 2018, 7:07:46 PM4/18/18
to Google Maps JavaScript API v3

Can  you give me example how you solved the problem ?

mohamm...@xipetech.com

unread,
Jun 21, 2018, 7:43:36 PM6/21/18
to [deprecated] Google Maps JavaScript API v3. Please use the latest post.
if (typeof(currentInfoWindow) != 'undefined') { 
                      currentInfoWindow.close(); 
                  } 
                  infowindow.open(map, marker); 
                  currentInfoWindow = infowindow; 

use typeof() function 

Trang Đinh Văn

unread,
Aug 29, 2018, 10:22:12 PM8/29/18
to [deprecated] Google Maps JavaScript API v3. Please use the latest post.
It works, thanks Gary B

Pascaru Sergiu

unread,
Oct 25, 2018, 6:38:59 PM10/25/18
to [deprecated] Google Maps JavaScript API v3. Please use the latest post.
its works for me very very fine, i spent 2 hours to find the correct answer.
Thx a lot ;-) 
Reply all
Reply to author
Forward
0 new messages