簡體   English   中英

試圖找到給定谷歌地圖緯度的經度與米的比率 Static API

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

我正在開展一個項目,希望將 Google 地圖 static 圖像轉換為更大的拼接地圖。

我創建了一個算法,它給出了開始和結束、緯度和經度,它將獲取該 lat,lng 對的谷歌地圖 Static 圖像,然后將 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))
}

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

我注意到的是,如果我將 getMetresToLng Ratio 更改為return (1 / Math.abs(111111 * Math.cos(lat))) * 2 ,拼接看起來更准確,只有幾十個像素,而不是幾乎圖像的一半。

帶 * 2 隨着時間 2

無 * 2 沒有時間 2

我的經度方程有問題嗎? 我知道 111111*cos(lat) 是一個粗略的估計,所以我想知道是否有更准確的公式

您使用了錯誤的地球半徑。 根據https://gis.stackexchange.com/questions/7430/what-ratio-scales-do-google-maps-zoom-levels-correspond-to中的答案,您需要使用半徑6371010來更新方程6378137米。

請注意,將瓷磚拼接在一起用於其他用途可能違反服務條款。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM