我想在touchmove事件(传单地图)中获取接触点的LatLng。我没有找到解决此问题的方法。有什么方法可以获取坐标?

$(document).on('touchmove', '#mapid', function(e) {
  //here i want to get the LatLng coordinates
)};

最佳答案

我看到两种方法。

一种是使用Leaflet的事件处理,例如做map.on('mousemove', function(ev){ ... });之类的事情。

该事件处理程序将收到一个Leaflet'MouseEvent',其中包括事件发生在地图上的点的LngLat。请参见http://leafletjs.com/reference-1.1.0.html#map-eventhttp://leafletjs.com/reference-1.1.0.html#mouseevent。是的,Leaflet在被告知收听TouchEvent时会收听PointerEventMouseEvent

另一种方法是使用map's containerPointToLatLng() conversion methodmouseEventToLatLng() method将像素坐标或鼠标事件转换为LatLng

10-06 04:24
查看更多