我正在做一个项目,希望将谷歌地图的静态图像转换成更大的、拼接在一起的地图。
我创建了一个算法,它给出了开始和结束、纬度和经度,它将获取该 lat、lng 对的谷歌地图静态图像,然后将 lng 增加获取图像的像素宽度,在本例中为 700px,使用使用几个公式确定像素与经度比的算法。
正如您在我的附件中看到的那样,这些公式似乎非常适合纬度,垂直平铺的图像几乎完美地排列在一起。
然而在水平方向上,经度增量似乎偏离了 2 倍,或者稍微多一点。
为了增加纬度,我使用恒定的米与纬度比
const metresToLatRatio = 0.001 / 111 // Get lat value from metres
const metresPerPxLat = getMetresPerPxLng(currentLat, zoom)
const latIncrement = metresToLatRatio * (metresPerPxLat * 700)
但是对于经度,我用从这个公式派生的变量替换了 metresToLngRatio 常数
const metresToLngRatio = getMetresToLngRatio(currentLat)
const metresPerPxLng = getMetresPerPxLng(currentLat, zoom)
lngIncrement = (metresToLngRatio * (metresPerPxLng * 700))
getMetresToLngRatio 和 getMetresPerPxLng 在哪里
function getMetresPerPxLng(lat, zoom = 19, scale = 2) {
return Math.abs((156543.03392 * Math.cos(lat * Math.PI / 180) / (2 ** zoom)) / scale)
}
function getMetresToLngRatio(lat) {
return 1 / Math.abs(111111 * Math.cos(lat))
}
getMetresPerPxLng 函数源自这篇文章和这个答案:https : //groups.google.com/g/google-maps-js-api-v3/c/hDRO4oHVSeM/https: //gis.stackexchange.com/questions/ 7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to
我注意到的是,如果我将 getMetresToLng Ratio 更改为return (1 / Math.abs(111111 * Math.cos(lat))) * 2
,拼接看起来更准确,只有几十个像素,而不是图像的近一半。
我的经度方程有问题吗?我知道 111111*cos(lat) 是一个粗略的估计,所以我想知道是否有更准确的公式