click event listener on styled map icons and labels

There is no API-based access to the POI’s .

But there is a possible workaround.

When you click on a POI an InfoWindow opens. It’s possible to modify the InfoWindow-prototype to be able to access the content of the InfoWindow without having a reference to the InfoWindow-instance.

      //store the original setContent-function
      var fx = google.maps.InfoWindow.prototype.setContent;

      //override the built-in setContent-method
      google.maps.InfoWindow.prototype.setContent = function (content) {
          //when argument is a node
          if (content.querySelector) {
              //search for the address
              var addr = content.querySelector('.gm-basicinfo .gm-addr');
              if (addr) {

                  alert(addr.textContent);
                  //leave the function here 
                  //when you don't want the InfoWindow to appear

              }
          }
          //run the original setContent-method
          fx.apply(this, arguments);
      };

Demo: http://jsfiddle.net/doktormolle/Vkf43/

Note: The selectors for the infowindow are not documented, they may change in the future

Leave a Comment