Hanfei Sun
Hanfei Sun

Reputation: 47051

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?

Upvotes: 7

Views: 8705

Answers (1)

Jonatas Walker
Jonatas Walker

Reputation: 14150

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

Upvotes: 8

Related Questions