模拟Google地图中的点击 [英] Simulate a click in a Google Map

查看:139
本文介绍了模拟Google地图中的点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在使用API​​ v3模拟用户点击Google地图时,在地理位置定位了他们的位置后,我试图模拟用户点击Google Map。要做:

  google.maps.event.trigger(地图,'点击',{
latLng:新谷歌.maps.LatLng(lat,lng)
});

但是现在我得到一个错误:


未捕获的TypeError:无法读取未定义的属性'wa'main.js:727

我需要模拟点击是因为我在CCK领域使用了Drupal,并且在点击引擎盖下进行这种操作,如果我将位置选择作为标记添加,则不会触发这些点击。 h2_lin>解决方案

地图对象的'click'事件需要

 
stop:null,
latLng:new google.maps.LatLng(40.0,-90.0)
}

google.maps.event.trigger(map,'点击',mev);

在此示例


I'm trying to simulate a user click on a Google Map, using API v3, after I geolocate their position when they write down their address.

I used to do:

google.maps.event.trigger(map, 'click', {
    latLng: new google.maps.LatLng(lat, lng)
});

But now I got an error:

Uncaught TypeError: Cannot read property 'wa' of undefined main.js:727

I need to simulate the click because I'm using Drupal with a CCK field, and it's doing this on clicks under the hood that are not triggered if I add the location pick as a marker.

解决方案

The map object's 'click' event takes a google.maps.MouseEvent object as parameter:

var mev = {
  stop: null,
  latLng: new google.maps.LatLng(40.0,-90.0)
}

google.maps.event.trigger(map, 'click', mev);

Live example here

这篇关于模拟Google地图中的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆