繁体   English   中英

以编程方式单击标记和地图

[英]Programmatically click on marker and map

我想在Google地图中以编程方式点击标记和地图。 我怎样才能做到这一点?

以编程方式触发标记点击/事件的正确方法是使用google.maps.event

google.maps.event.trigger(marker, 'click')

保持对要以编程方式单击的对象的引用,并在其上调用触发器事件。

http://code.google.com/apis/maps/documentation/javascript/reference.html

你可以用这个代码点击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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM