问题描述
map.layerPointToLatLng(map.latLngToLayerPoint(L.latLng(40.687, -73.9035)))
产生
不精确度似乎过高,尤其是对于经度.
The imprecizeness seems to be unreasonably high, especially for the longitude.
map.getZoom()
产生
map.getSize()
产生
有没有提高精确度的方法?
Is there a way to increase preciseness?
推荐答案
如果我正确理解,则首先将LatLng转换为当前地图视图(缩放比例为9,无论视图的端口尺寸如何)上的像素位置.
If I understand correctly, you first convert your LatLng to a pixel position on your current map view (zoom 9, whatever view port dimensions).
然后,您将该像素位置转换回LatLng,并注意到与原始LatLng不一致.
Then you convert that pixel position back to a LatLng, and notice a discrepancy with your original LatLng.
在我看来,您只是观察像素舍入的效果: map.latLngToLayerPoint
将为您提供整数像素坐标,因此就实际距离而言,您的精度不会比像素覆盖的精度好.
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.
在9缩放和纽约纬度(40.687)下,比例为86px约为20公里,因此每个像素约为230m.
At zoom 9 and New York latitude (40.687), the scale is about 20km for 86px, so about 230m per pixel.
您报告的2个LatLng坐标之间的距离约为103m.因此,它恰好在单个像素内.
The distance between the 2 LatLng coordinates you report is about 103m. Therefore it is well within a single pixel.
实时演示: https://jsfiddle.net/3v7hd2vx/149/(结果是在控制台中打印)
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).
这篇关于传单测量转换的准确性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!