首页 > 解决方案 > 采取经纬度openlayers

问题描述

大家好,我有一个问题,我正在创建一个地图,在其中创建两个指针(起点 - 目的地),我可以根据文本框中的地址找到点。与在几个位置一样,地址未定义我想要做的是在用户拖动指针时获取指针的纬度和经度。到目前为止,我只能使指针移动,但无法恢复它们的经纬度。我分享了我正在执行该部分的代码部分。

//**** para mover el puntero Origen *****
var modifyOrigen = new ol.interaction.Modify({source: sourceOrigen});


   map.addInteraction(modifyOrigen);
   function addInteractions(e) {
   drawOrigen = new ol.interaction.Draw({
    source: sourceOrigen,
   type: iconoParadaCoche.value
  });

 map.addInteraction(draw);
 snapOrigen = new ol.interaction.Snap({source: sourceOrigen}); 
 map.addInteraction(snapOrigen);

}

 //**** para mover el puntero Destino *****
 var modifyDestino = new ol.interaction.Modify({source: 
 sourceDestino});
 map.addInteraction(modifyDestino);

 function addInteractions() {
  drawDestino = new ol.interaction.Draw({

    source: sourceDestino,
   type: iconoParadaCoche.value

  });
  map.addInteraction(drawDestino);
  snapDestino = new ol.interaction.Snap({source: sourceDestino});
   map.addInteraction(snapDestino);

 }

标签: javascriptopenlayers

解决方案


您应该能够在 modifyend 事件中获取坐标

modifyOrigen.on('modifyend', function(evt) { 
  console.log(evt.features.item(0).getGeometry().getCoordinates());
});

推荐阅读