开发者

Programmatically click on marker and map

开发者 https://www.devze.com 2023-01-14 14:33 出处:网络
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.ev

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消