Skip to content Skip to sidebar Skip to footer

Preciseness Of Leaflet Measurement Conversions

map.layerPointToLatLng(map.latLngToLayerPoint(L.latLng(40.687, -73.9035))) results in {lat: 40.686886382151116, lng: -73.90228271484375} The imprecizeness seems to be unreasonab

Solution 1:

If I understand correctly, you first convert your LatLng to a pixel position on your current map view (zoom 9, whatever view port dimensions).

Then you convert that pixel position back to a LatLng, and notice a discrepancy with your original LatLng.

It seems to me that you simply observe the effect of pixel rounding: map.latLngToLayerPoint will give you integer pixel coordinates, hence your precision will be no better than what a pixel covers in terms of actual distance.

At zoom 9 and New York latitude (40.687), the scale is about 20km for 86px, so about 230m per pixel.

The distance between the 2 LatLng coordinates you report is about 103m. Therefore it is well within a single pixel.

Live demo: https://jsfiddle.net/3v7hd2vx/149/ (results are printed in the console)

You can play with map zoom to see the precision improving, as each pixel will cover a smaller distance (area actually).

Post a Comment for "Preciseness Of Leaflet Measurement Conversions"