Javascript 谷歌地图apiv3';单击';和';德拉根德';单个侦听器

Javascript 谷歌地图apiv3';单击';和';德拉根德';单个侦听器,javascript,google-maps-api-3,Javascript,Google Maps Api 3,通过点击我的代码来检索lat,很长时间,效果很好。想知道是否可以在单个事件侦听器中组合“click”和“dragend”。如果有合适的选择,我将不胜感激 这就是我一直在做的 google.maps.event.addListener(map,'click', function(event) { document.getElementById("latbox").value = event.latLng.lat(); document.getElementById("lngbox"

通过点击我的代码来检索lat,很长时间,效果很好。想知道是否可以在单个事件侦听器中组合“click”和“dragend”。如果有合适的选择,我将不胜感激

这就是我一直在做的

google.maps.event.addListener(map,'click', function(event) {
    document.getElementById("latbox").value = event.latLng.lat();
    document.getElementById("lngbox").value = event.latLng.lng();
    addMarker(event.latLng);
  });
}

 function addMarker(location) {

if (!marker) {

    marker = new google.maps.Marker({
    position: location,
    map: map,
    draggable:true,
    animation: google.maps.Animation.DROP
    });
}
// Otherwise, simply update its location on the map.
else { marker.setPosition(location); }
 }

我尝试过这样做
google.maps.event.addListener(映射,'click','dragend',函数(event)
,但没有效果。如果有人想修改这个
marker.setPosition(位置)
拥有
动画:google.maps.animation.DROP
。提前感谢。

没有内置方法为多个事件应用侦听器

当您的问题是不想两次定义回调函数时,您可以使用非匿名函数或为1个事件定义侦听器,并在另一个事件触发时触发该事件:

google.maps.event.addListener( map, 'click',
                              function(e){ alert('clicked or dragged');} );
google.maps.event.addListener( map, 'dragend', function(){
                              google.maps.event.trigger(this, 'click');} );
与动画相关:
除了使用标记方法(setAnimation、setPosition)设置标记选项外,还可以使用方法setOptions一次设置多个选项:

marker.setOptions({ position  : location,
                    animation : google.maps.Animation.DROP});

谢谢你帮了大忙。我们将使用这些技巧。