Reputation: 736
I got a map on a site. and I try to fire an click on a marker by clicking on a link (outside the map) on the side of the map.
Here's the code:
<a id="ctl00_ctl00_cphMain_main_rptTouristique_ctl00_lnk" onclick="javascript:google.maps.event.trigger(markerArray[0],'click') ">Le Vieux Montréal</a>
Note: markerArray is an array of all the markers on the map.
Note: I work with the version 3 of the API (the current one)
Upvotes: 4
Views: 7483
Reputation: 824
I am sure like you have to trigger an click event externally which means you are triggering a function, so you can call the same function to show that the marker is triggered. For Example,
function callAfterMarker(){
alert("Market Clicked");
}
google.maps.event.addListener(marker, 'click', function() {
callAfterMarker();
});
<a href="javascript:callAfterMarker();">Address Name</a>";
Plus you have the marker array with you so you can decide from which marker your function or position need to be calculated and executed. (i.e) If you want to pass any marker related information to that function.
Hope this helps!
Upvotes: 1
Reputation: 11
I'm not sure if you are, but I believe you need to set-up your click function.
google.maps.event.addListener(marker, 'click', function() {
map.setCenter(marker.position);
});
<a href="javascript:google.maps.event.trigger(markerArray[0],'click')">Address Name</a>";
Upvotes: 1