您需要在GDirections对象上为addoverlay事件添加一个处理程序:
GEvent.addListener(gdir, "addoverlay", onGDirectionsAddOverlay);
当您的onGDirectionsAddOverlay处理程序被调用时,您可以遍历新标记并将它们替换为可拖动的副本:
for (var i = 0; i <= gdir.getNumRoutes(); i++)
{
var originalMarker = gdir.getMarker(i);
latLngs[i] = originalMarker.getLatLng();
icons[i] = originalMarker.getIcon();
newMarkers[i] = new GMarker(latLngs[i], { icon: icons[i], draggable: true, title: 'Kan flyttes' });
map.addOverlay(newMarkers[i]);
// add stuff to your newMarkers[i] drag end event...
// ...
//Bind 'click' event to original markers 'click' event
copyClick(newMarkers[i], originalMarker);
// Now we can remove the original marker safely
map.removeOverlay(originalMarker);
}
您可以在此处找到一个工作示例(来源)。