Reputation: 3886
I want to click on a marker and map programmatically, in Google Maps. How can I do this?
Upvotes: 14
Views: 10860
Reputation: 2024
The right way to trigger a marker click/event programmatically is by using google.maps.event
:
google.maps.event.trigger(marker, 'click')
Upvotes: 8
Reputation: 1391
you can use this code for firing click on mao...
function onload() { var map= new google.maps.Map(document.getElementById('map'), { center: new google.maps.LatLng(37.4419, -122.1419), zoom: 14, mapTypeId: google.maps.MapTypeId.ROADMAP, disableDefaultUI: true }); google.maps.event.addListener(map, 'click', function(event){ alert('Lat: ' + event.latLng.lat() + ' and Longitude is: ' + event.latLng.lng()); //here you can do anything u want to code }
Upvotes: -2
Reputation: 1857
Keep a reference to the object you want to click programmatically and call the trigger event on it.
http://code.google.com/apis/maps/documentation/javascript/reference.html
Upvotes: 4