2014-03-28 42 views
2

我使用的是OpenLayers,我已經找到拖動標記的實現,但沒有關於如何返回拖動位置的文檔。我已經試過這樣:我怎樣才能拖動一個標記,並得到lon/lat

drag = new OpenLayers.Control.DragFeature(vectors, { 
    autoActivate: true, 
    onComplete: function() { 
    alert('hello') 
    } 
}); 

不退還其標記被拖所以我不能拖後得到其經度或緯度。

回答

2

實際上the official documentation明確指出onComplete回調的第一個參數是受影響的功能。您可以輕鬆地檢查處理程序中的功能。

舉一個例子去http://dev.openlayers.org/examples/drag-feature.html,打開瀏覽器的JS控制檯,並執行這個片段:

map.addControl(new OpenLayers.Control.DragFeature(vectors, { 
    autoActivate: true, 
    onComplete: function (feature) { 
    alert('x=' + feature.geometry.x + ', y=' + feature.geometry.x); 
    } 
})); 

然後添加一個點,並嘗試拖動。