How to get a click event when a user clicks a (business) place on the map

Editor’s note: this answer was applicable until version 3.23. Since version 3.24 released in 2016, you can use clickableIcons map option. See this answer.


Basically there is no option to handle clicks on the POI’s.

Of course you can simply hide these features via styles, but when you want to keep them visible on the map, here’s a workaround(based on: click event listener on styled map icons and labels):

When you click a POI an InfoWindow opens, that’s where you may get access.

Override the setPosition-method of the InfoWindow-prototype so that it triggers a click on the map.

//keep a reference to the original setPosition-function
var fx = google.maps.InfoWindow.prototype.setPosition;

//override the built-in setPosition-method
google.maps.InfoWindow.prototype.setPosition = function () {

  //logAsInternal isn't documented, but as it seems
  //it's only defined for InfoWindows opened on POI's
  if (this.logAsInternal) {
    google.maps.event.addListenerOnce(this, 'map_changed',function () {
      var map = this.getMap();
      //the infoWindow will be opened, usually after a click on a POI
      if (map) {
        //trigger the click
        google.maps.event.trigger(map, 'click', {latLng: this.getPosition()});
      }
    });
  }
  //call the original setPosition-method
  fx.apply(this, arguments);
};

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

Leave a Comment