简体   繁体   English

试图找到给定谷歌地图纬度的经度与米的比率 Static API

[英]Trying to find the longitude to metres ratio given a latitude for Google Maps Static API Stitching

I'm working on a project that hopes to convert Google maps static images into larger, stitched together maps.我正在开展一个项目,希望将 Google 地图 static 图像转换为更大的拼接地图。

I have created an algorithm that given a starting and ending, latitude and longitude, it will fetch the Google Maps Static image for that lat,lng pair, then increment lng by the pixel width of the fetched image, in this case 700px, using an algorithm for determining pixel to longitude ratio using a couple of formulas.我创建了一个算法,它给出了开始和结束、纬度和经度,它将获取该 lat,lng 对的谷歌地图 Static 图像,然后将 lng 增加获取图像的像素宽度,在本例中为 700px,使用使用几个公式确定像素与经度比的算法。

The formulas seem to be working perfectly for latitude, as you can see in my attachment, the vertically tiling images line up almost perfectly.正如您在我的附件中看到的那样,这些公式似乎非常适合纬度,垂直平铺的图像几乎完美地排列在一起。

Yet horizontally, the longitude increment seems to be off by a factor of 2, or slightly more.然而在水平方向上,经度增量似乎偏离了 2 倍,或者稍微多一点。

To increment latitude, I use a constant metres to latitude ratio为了增加纬度,我使用恒定的米与纬度比

const metresToLatRatio = 0.001 / 111 // Get lat value from metres
const metresPerPxLat = getMetresPerPxLng(currentLat, zoom)
const latIncrement = metresToLatRatio * (metresPerPxLat * 700)

But for longitude, I replaces the metresToLngRatio constant with a variable derived from this formula但是对于经度,我用从这个公式派生的变量替换了 metresToLngRatio 常数

const metresToLngRatio = getMetresToLngRatio(currentLat)
const metresPerPxLng = getMetresPerPxLng(currentLat, zoom)
lngIncrement = (metresToLngRatio * (metresPerPxLng * 700))

Where getMetresToLngRatio and getMetresPerPxLng are 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))
}

The getMetresPerPxLng function is derived from this post and this answer: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 The getMetresPerPxLng function is derived from this post and this answer: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

What I noticed is that if I change getMetresToLng Ratio to return (1 / Math.abs(111111 * Math.cos(lat))) * 2 , the stitching appears more accurate, only off by a few tens of pixels, instead of almost half the image.我注意到的是,如果我将 getMetresToLng Ratio 更改为return (1 / Math.abs(111111 * Math.cos(lat))) * 2 ,拼接看起来更准确,只有几十个像素,而不是几乎图像的一半。

With * 2带 * 2 随着时间 2

Without * 2无 * 2 没有时间 2

Am I doing something wrong with my longitude equation?我的经度方程有问题吗? I know that 111111*cos(lat) is a rough estimate, so I'm wondering if there's a more accurate formula我知道 111111*cos(lat) 是一个粗略的估计,所以我想知道是否有更准确的公式

You are using the wrong earth radius.您使用了错误的地球半径。 From the answer in https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to , you need to update the equation using a radius of 6371010 instead of 6378137 meters.根据https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to中的答案,您需要使用半径6371010来更新方程6378137米。

Please note that stitching tiles together for some other use is likely a violation of the Terms of Service.请注意,将瓷砖拼接在一起用于其他用途可能违反服务条款。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM