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

In leaflet, how to calculate the Pixel Distance between two LatLng object?

有一个 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

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

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

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

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

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