Skip to content

Google Maps API – Forcing click on Marker

I figured I’d make a quick post about a problem I had while working with Google Maps API; this problem came up when I needed a DOM element to trigger a click on a Marker so an InfoBubble came up (http://blog.michaelhelmick.com/2011/04/23/google-maps-api-multiple-markers-multiple-infowindowsinfobubbles/)

The Problem

I needed to trigger a ‘click’ on a certain marker when I clicked a DOM Element. And you can’t just do markerInstance.click();

The Solution

To force the click, you need to call google.maps.event.trigger which takes two params (instance, event)
So, in our code, when anything with the class ‘forceMarkerClick’ is clicked, it calls that event and uses the item in our markerArray with the index that is available on the anchors data-markerId attribute as the instance and ‘click’ as the event.

For more information about google.maps.event.trigger, please view the Google Maps API documentation on it:
http://code.google.com/apis/maps/documentation/javascript/reference.html#event

Hope this helps!

2 Comments

  1. sang86yi sang86yi

    I can’t speak English. but, I want talk you. Thank you very much. I love you so much.
    감사합니다.
    ありがとうございます。

  2. Thanks you very much for your example, it make me can trigger click on multiple marker

Leave a Reply

Your email address will not be published. Required fields are marked *