Auto close infowindow when another is open (Google Map developer)
The idea is to declare a new global variable "currentinfo" and listen to every marker, when an infowindow is open and user click on any one close the previous one which is stored on the declared variable "currentinfo", then affect the current infowindow to the "currentinfo", so the code is like bellow:
var currentinfo = null; // set the variable top null at first run.
var infowindow = new google.maps.InfoWindow({ content: "infowindow content here" }); google.maps.event.addListener(marker, 'click', function() {
if(currentinfo) { currentinfo.close();}
infowindow.open(map, marker);
currentinfo = infowindow; });The Red lines are the magic lines, use them on your application if it differs from the bellow algorithm.
If you like this article, please share it on facebook, tweet it and +1 it to spread it :) !
Auto close infowindow when another is open (Google Map developer)
Reviewed by Mhr
on
22:27
Rating:
No comments
No Backlinks please, Comments are under moderation !