I'm using OpenLayers and I have already found the implementation of dragging a marker, but there's no documentation about how to return the dragged position. I've tried this:

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

It doesn't return which marker was dragged so I can't get its longitude or latitude after dragging.

有帮助吗?

解决方案

Actually the official documentation clearly states that the first argument to the onComplete callback is the affected feature. You can easily inspect its features in the handler.

For an example go to http://dev.openlayers.org/examples/drag-feature.html, open your browser's JS console and execute this snippet:

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

Then add a point and try dragging it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top