Monday, June 3, 2024
158
rated 0 times [  160] [ 2]  / answers: 1 / hits: 19151  / 13 Years ago, wed, february 8, 2012, 12:00:00

What I'd like to do is to invoke the click handler on a marker. So this is my code :



var marker = new google.maps.Marker({
position: location,
map: map,
title: title
});

google.maps.event.addListener(marker, 'click', function() {
alert(clicked);
});

marker.click();


but I cannot see any alert...


More From » google-maps-api-3

 Answers
16

It's possible to trigger any Maps API event listener on any object using the google.maps.event.trigger function.



You'll probably want to pass in a mock MouseEvent object, depending on what your event listener(s) do with it.



Example:



google.maps.event.trigger(marker, 'click', {
latLng: new google.maps.LatLng(0, 0)
});

[#87589] Monday, February 6, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yamileth

Total Points: 53
Total Questions: 96
Total Answers: 112

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;