How to trigger the onclick event of a marker on a Google Maps V3?

后端 未结 2 642
失恋的感觉
失恋的感觉 2020-11-29 16:35

How do I trigger the onclick event of a marker on a Google Maps from outside the map?

I use version 3 of the API. I\'ve seen many tutorials

相关标签:
2条回答
  • 2020-11-29 16:58

    I've found out the solution! Thanks to Firebug ;)

    //"markers" is an array that I declared which contains all the marker of the map
    //"i" is the index of the marker in the array that I want to trigger the OnClick event
    
    //V2 version is:
    GEvent.trigger(markers[i], 'click');
    
    //V3 version is:
    google.maps.event.trigger(markers[i], 'click');
    
    0 讨论(0)
  • 2020-11-29 16:58

    For future Googlers, If you get an error similar below after you trigger click for a polygon

    "Uncaught TypeError: Cannot read property 'vertex' of undefined"
    

    then try the code below

    google.maps.event.trigger(polygon, "click", {});
    
    0 讨论(0)
提交回复
热议问题