Programmatically click on marker and map
I want to click on a开发者_StackOverflow社区 marker and map programmatically, in Google Maps. How can I do this?
The right way to trigger a marker click/event programmatically is by using google.maps.event
:
google.maps.event.trigger(marker, 'click')
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
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 }
精彩评论