所以我用 gmaps.js 加载我的谷歌地图,这使得它更容易使用。问题是某些 native 函数不可用,特别是我需要 addListenerOnce
我这样加载我的地图:
searchmap = new GMaps({
div: '#searchmap',
lat: '40.7142691000',
lng: '-74.0059729000',
});
我可以像这样添加一个事件监听器:
searchmap.addListener('idle', function() {
//do something here
});
但是我无法添加 native addListenerOnce
,所以我假设我可以这样做(这是行不通的):
google.maps.event.addListenerOnce(searchmap, 'idle', function(){
//do something
});
那么知道如何使用 addListenerOnce
了吗? (很明显,我是一个 JS 新手......在 github 仓库中进行了大量的搜索都没有帮助)
最佳答案
您需要将监听器添加到 native google.maps.Map 对象:
http://hpneo.github.io/gmaps/documentation.html#GMaps-map
这应该有效:
google.maps.event.addListenerOnce(searchmap.map, 'idle', function(){
//do something
});
关于javascript - gmaps.js 使用 native Google Maps API v3 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19825218/