問題描述
我正在嘗試使用 API v3 模擬用戶在他們寫下他們的地址時對他們的位置進行地理定位后點擊 Google 地圖.
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.
我曾經(jīng)這樣做過:
google.maps.event.trigger(map, 'click', {
latLng: new google.maps.LatLng(lat, lng)
});
但現(xiàn)在我得到一個錯誤:
But now I got an error:
Uncaught TypeError: Cannot read property 'wa' of undefined main.js:727
Uncaught TypeError: Cannot read property 'wa' of undefined main.js:727
我需要模擬點擊,因為我正在使用帶有 CCK 字段的 Drupal,如果我將位置選擇添加為標(biāo)記,它會在引擎蓋下的點擊上執(zhí)行此操作.
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.
推薦答案
地圖對象的點擊"事件需要一個 google.maps.MouseEvent 對象作為參數(shù):
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);
現(xiàn)場示例
這篇關(guān)于在 Google 地圖中模擬點擊的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!