Skip to content Skip to sidebar Skip to footer

How To Close Infowindow From Sidebar In The Second Click In Google Maps Api Places

I'm using this code: http://gmaps-samples-v3.googlecode.com/svn/trunk/places/places-search.html I'd like on the second click of the sidebar, to close the infowindow (var iw). f

Solution 1:

Change the showInfoWindow function in the example to check to see if the infowindow is open and the same infowindow, then just close it, otherwise do the required processing to get the contents. Need to add a property to the marker so you can tell whether it is the same one or not.

functionshowInfoWindow(i) {
    returnfunction(place, status) {
      if (!!iw && iw._iwId == i) {
        iw.close();
        iw = null;
      } else {
        if (iw) {
          iw.close();
          iw = null;
        }
        if (status == google.maps.places.PlacesServiceStatus.OK) {
          iw = new google.maps.InfoWindow({
            content: getIWContent(place),
            _iwId:i
          });
          iw.open(map, markers[i]);        
        }
      }
    }
  }

working example

Solution 2:

Try setting the content to '' (standard way for closing the infowindow) like this :

tr.onclick=function(){
        google.maps.event.trigger(markers[i],'click');
        console.log('markers[i]: '+i);

    if (isInfoWindowOpen(iw)){
        // do something if IW is open
        iw.close(map,markers[i]);
        // Set the content to ''
        iw.setContent('');
    }
}

Post a Comment for "How To Close Infowindow From Sidebar In The Second Click In Google Maps Api Places"