Comment déclencher l'événement onclick d'un marqueur sur un Google Maps V3?

Comment déclencher l'événement onclick d'un marqueur sur Google Maps depuis l'extérieur de la carte?

J'utilise la version 3 de L'API. J'ai vu beaucoup de tutoriels pour la version 2, mais je ne peux pas le trouver pour la version 3.

J'ai un tableau global (nommé marqueurs) contenant tous les marqueurs de la carte (google.cartographie.Marqueur). Maintenant, je veux faire quelque chose comme:

markers[i].click(); //I know it's not working, but you get the idea...

//Next line seems to be the way in v2, but what's the equivalent in v3?
GEvent.trigger(markers[i], 'click');

Merci pour votre aide et si vous avez besoin de plus d'informations, faites le moi savoir!

123
demandé sur AlexV 2010-04-28 19:33:19

2 réponses

J'ai trouvé la solution! Merci à 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');
318
répondu AlexV 2015-04-09 15:33:45

Pour les futurs Googlers, Si vous obtenez une erreur similaire ci-dessous après avoir déclenché cliquez sur un polygone

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

Ensuite, essayez le code ci-dessous

google.maps.event.trigger(polygon, "click", {});
5
répondu Ergec 2016-03-29 13:42:47