我想跟踪地图中心的坐标。到目前为止我一直在使用这个:
// On Drag End
google.maps.event.addListener(map, 'dragend', function() {
$('.map_center_coords .latitude').html( map.getCenter().lat() );
$('.map_center_coords .longitude').html( map.getCenter().lng() );
});
它的工作原理是在拖动事件结束时获取坐标。
问题是我现在正在使用map.panTo
移动到某个位置。
基本上有一个活动吗"whenever the center has *finished* moving in any way"
?
正如 geocodezip 提到的,我忘记了center_changed
事件。但是当拖动/平移地图时,该事件会连续触发。
理想情况下,我正在寻找一个在完成任何拖动/平移后仅触发一次的事件。
改为观察空闲事件(当地图在平移或缩放后变为空闲时会触发此事件):
google.maps.event.addListener(map,'idle',function(){
if(!this.get('dragging') && this.get('oldCenter') && this.get('oldCenter')!==this.getCenter()) {
//do what you want to
}
if(!this.get('dragging')){
this.set('oldCenter',this.getCenter())
}
});
google.maps.event.addListener(map,'dragstart',function(){
this.set('dragging',true);
});
google.maps.event.addListener(map,'dragend',function(){
this.set('dragging',false);
google.maps.event.trigger(this,'idle',{});
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)