Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

There is a latlng distanceTo method: 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

It calculates the distance (in meters) between two LatLng. However, sometimes I needs to know how many pixels are there between two points. Does anyone have ideas about this?

like image 288
Hanfei Sun Avatar asked May 26 '15 11:05

Hanfei Sun


1 Answers

You can convert your coordinates to screen points using:

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

And then measure the distance between the two points with:

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

like image 168
Jonatas Walker Avatar answered Nov 17 '22 18:11

Jonatas Walker