Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing info windows in google maps by clicking the map?

I'm making a mobile web app.

Part of the app drops several markers, which can be clicked to open info windows. It irritates me that these do not go away if you continue using the map without acknowledging them, as in the iOS maps app.

Is there a way to set it so that if the user clicks the underlying map, all open info windows are closed?

like image 959
temporary_user_name Avatar asked Apr 05 '12 04:04

temporary_user_name


People also ask

What is info window in Google map?

An InfoWindow displays content (usually text or images) in a popup window above the map, at a given location. The info window has a content area and a tapered stem. The tip of the stem is attached to a specified location on the map.

How do I customize the Google Maps window pop up?

You can modify the whole InfoWindow using jquery alone... var popup = new google. maps. InfoWindow({ content:'<p id="hook">Hello World!

How do I close an AGM window?

Disable auto-pan on open. By default, the info window will pan the map so that it is fully visible when it opens. Sets the open state for the InfoWindow. You can also call the open() and close() methods.


2 Answers

Try this:

google.maps.event.addListener(map, "click", function(event) {     infowindow.close(); }); 

It is quite simple an should work as well.

like image 155
Marcus Rommel Avatar answered Sep 20 '22 14:09

Marcus Rommel


add listener to map's click event and close infoboxes in its handler

google.maps.event.addListener(map, "click", function(event) {     for (var i = 0; i < ibArray.length; i++ ) {  //I assume you have your infoboxes in some array          ibArray[i].close();     } }); 

I do that on typical websites, but don't see any reason it wouldn't work on mobile

like image 30
slawekwin Avatar answered Sep 20 '22 14:09

slawekwin