how to close all InfoWindow before opening new infowindow?

3,907 views
Skip to first unread message

sudhakar Kanniyan

unread,
Jul 23, 2010, 3:39:11 PM7/23/10
to Google Maps JavaScript API v3
I have hyperlink out of google map. Where user do mouse over the
hyperlink and infowindows opens in google map. It works fine for me
but When I apply same for more than one hyperlink in a page, It keep
opening infowindow in google map for earch hyperlink . I want all the
infowindow to be closed and open just current mouse over infowindow. I
call showinfo method in mouse over. Please help me in closing the
infowindow.

function showinfo(LocationName,address,image)
{

var infoWindowContent = '<p style="font-size:14pt;font-weight:
bold;" > '+LocationName+'</p><p>'+address+'</p>';
geocoder.geocode( { 'address': address}, function(results,
status) {
if (status == google.maps.GeocoderStatus.OK)
{
marker = new
google.maps.Marker({
position: results[0].geometry.location,
map: map , icon: image
});
map.setCenter(results[0].geometry.location);

mapBounds.extend(results[0].geometry.location);
var infoWindow1 = new google.maps.InfoWindow();

makeMarker({position:
results[0].geometry.location, content: infoWindowContent , icon:
image });
infoWindow1.setOptions({maxWidth: 200 });
infoWindow1.setContent(infoWindowContent);

infoWindow1.open(map, marker);
}
else
{
alert("Geocode was not successful for the
following reason: " + status);
}
});

}

function makeMarker(options){
var pushPin = new google.maps.Marker({map:map});
pushPin.setOptions(options);
google.maps.event.addListener(pushPin, 'click', function(){
infoWindow.setOptions(options);
infoWindow.open(map, pushPin);
});
markerArray.push(pushPin);
return pushPin;
}

geoco...@gmail.com

unread,
Jul 24, 2010, 10:27:43 AM7/24/10
to Google Maps JavaScript API v3
On Jul 23, 12:39 pm, sudhakar Kanniyan <sudhakarkanni...@gmail.com>
wrote:
> I have hyperlink out of google map. Where user do mouse over the
> hyperlink and  infowindows opens in google map. It works fine for me
> but When I apply same for more than one hyperlink in a page, It keep
> opening infowindow in google map for earch hyperlink . I want all the
> infowindow to be closed and open just current mouse over infowindow. I
> call showinfo method in mouse over. Please help me in closing the
> infowindow.

Your code got mangled by the groups interface. These examples may
help you:
http://www.geocodezip.com/v3_markers_infowindows.html
http://www.geocodezip.com/v3_markers_normal_colored_infowindows.html
http://www.geocodezip.com/v3_MW_example_map1.html

There is only one infowindow shown at a time, but they use the marker
"click" listener to open the infowindow.

-- Larry

sudhakar kanniyan

unread,
Jul 26, 2010, 11:05:59 AM7/26/10
to google-map...@googlegroups.com
Actually as in the example it works in my website of google map. I do have 10 html hyperlink outside of the google map for each location. so when user click on the location hyperlink , infowindows opens in the google map.  For each location hyperlink  click  an infowindow opens in google. My question how do I close infowindow before I open new infowindow if user click on the html hyperlink.
 
Thanks
Sudhakar

--
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.


geoco...@gmail.com

unread,
Jul 26, 2010, 11:35:15 AM7/26/10
to Google Maps JavaScript API v3
On Jul 26, 8:05 am, sudhakar kanniyan <sudhakarkanni...@gmail.com>
wrote:
> Actually as in the example it works in my website of google map. I do have
> 10 html hyperlink outside of the google map for each location. so when user
> click on the location hyperlink , infowindows opens in the google map.  For
> each location hyperlink  click  an infowindow opens in google. My question
> how do I close infowindow before I open new infowindow if user click on the
> html hyperlink.

I can't say from the information you posted. If you look at my
examples, you might be able to figure it out, if you post a link to
your map, I might.

-- Larry

>
> Thanks
> Sudhakar
>
> On Sat, Jul 24, 2010 at 9:27 AM, geocode...@gmail.com
> <geocode...@gmail.com>wrote:
> > google-maps-js-a...@googlegroups.com<google-maps-js-api-v3%2B­unsub...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-maps-js-api-v3?hl=en.- Hide quoted text -
>
> - Show quoted text -

sudhakar kanniyan

unread,
Jul 26, 2010, 11:44:18 AM7/26/10
to google-map...@googlegroups.com
I figured out and fixed the issue . Thanks for your support.

To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.

DanZ

unread,
Aug 24, 2011, 10:08:58 PM8/24/11
to google-map...@googlegroups.com
Reading this thread I'm not sure if info windows should be closed before new ones are opened. This example does not call close before open: http://www.geocodezip.com/v3_markers_infowindows.html

Assuming a global info window, what's the right thing to do?
Set a position or pass marker during open()?
Call close before open?
Check what marker was selected previously before closing?
Create a separate info window per marker, so that every marker owns its own window?

Chris Broadfoot

unread,
Aug 24, 2011, 10:15:05 PM8/24/11
to google-map...@googlegroups.com
Hi Dan,

The recommendation is to only have one InfoWindow, changing the content and updating its position (or using the "open" method).

This is the technique used in the example you linked.

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.

Dan Zivkovic

unread,
Aug 24, 2011, 11:44:52 PM8/24/11
to google-map...@googlegroups.com
Roger, one info window.

Do you recommend setContent + close() + open(marker) or simply setContent() + setPosition().

Also, I'm finding that the window wipes out the content it's showing after it's closed. So when I go back to the same pin and call setContent(myInfoDiv) the content is null :)
Reply all
Reply to author
Forward
0 new messages