0

I have seen plenty of posts and answered about how to call the .close() method on infowindows that I create. That is not my problem - my question is about infowindows that are built in to the map. For instance, if I click on Times Square, it opens an infowindow. How do I programmatically close that infowindow since I am not the one calling for it's creation.

blubberbo
  • 4,441
  • 4
  • 23
  • 36
  • Do you want to close it or not allow it to be opened? – geocodezip Dec 11 '16 at 22:31
  • close it. for instance, when i click on the map, to have the open window(s) close – blubberbo Dec 11 '16 at 22:32
  • related question: [click event listener on styled map icons and labels](http://stackoverflow.com/questions/21486868/click-event-listener-on-styled-map-icons-and-labels) – geocodezip Dec 11 '16 at 22:50
  • related question: [How to get a click event when a user clicks a (business) place on the map](http://stackoverflow.com/questions/24234106/how-to-get-a-click-event-when-a-user-clicks-a-business-place-on-the-map) – geocodezip Dec 11 '16 at 22:52
  • thank you, but that's just how to get the event, not how to close a window that has already been opened. For instance, how to close all open windows – blubberbo Dec 11 '16 at 23:22
  • What do you mean by "all open windows"? There should only be one from the POIs, any others should have been created by your code, and therefor controllable/closable by it. To close the POI's automatic infowindow, you need a reference to it. – geocodezip Dec 12 '16 at 04:10
  • yeah, just the one from the POI. Ah, so you are saying get the reference via your link above and then use that to close it? Sorry, I didn't get that before. Although I am not quite sure how to get the reference to the infowindow from the events mentioned above – blubberbo Dec 12 '16 at 04:20

1 Answers1

0

Your question is not clear but here is my attempt to answer it.Put this line at the beginning of your code that creates the map

lastWindow=null;

.Then change the following code to your needs

google.maps.event.addListener(marker, 'click', function() {
   if (lastWindow) lastWindow.close();
   this.infowindow.open(map, this);
   lastWindow=infowindow;
});

That should close all infowindows that are open.