在传单中,如何计算两个LatLng对象之间的像素距离?

Han*_*Sun 6 gis leaflet mapbox

有一个latlng distanceTo方法:http: //leafletjs.com/reference.html#latlng

distanceTo( <LatLng> otherLatlng )  Number  Returns the distance (in
meters) to the given LatLng calculated using the Haversine formula.
See description on wikipedia
Run Code Online (Sandbox Code Playgroud)

它计算两个LatLng之间的距离(以米为单位).但是,有时我需要知道两点之间有多少像素.有没有人有这个想法?

Jon*_*ker 5

您可以使用以下方法将坐标转换为屏幕点:

http://leafletjs.com/reference.html#map-latlngtolayerpoint

然后测量两点之间的距离:

http://leafletjs.com/reference.html#point-distanceto