地图上的 Google Map Api v3 拖动事件 [英] Google Map Api v3 drag event on map

查看:21
本文介绍了地图上的 Google Map Api v3 拖动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用谷歌地图 v3 api.我需要检测地图上的拖动事件.无论是在地图上拖动以移动到附近的地理位置还是在标记上拖动.当任一事件发生时,我需要一些 javascript 函数来运行.

I am using google map v3 api. I need to detect the drag event on the map. Be it the drag on the map to move to a nearby geographical location or a drag on the marker. I need some javascript function to run when either of the events occur.

推荐答案

Map 对象和 Marker 对象都有 drag 事件,尽管您可能想要 dragend 以便您可以在用户完成拖动时做某事,而不是在用户拖动时做某事.

Both Map objects and Marker objects have drag events, although you probably want dragend so that you can do something when a user is done dragging rather than do something while a user is dragging.

所以你可以这样做:

google.maps.event.addListener(map, 'dragend', function() { alert('map dragged'); } );
google.maps.event.addListener(marker, 'dragend', function() { alert('marker dragged'); } );

这篇关于地图上的 Google Map Api v3 拖动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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