簡體   English   中英

谷歌地圖 LatLng 和 LatLngBounds 返回不同的結果

[英]Google maps LatLng and LatLngBounds returning different results

我目前正在學習使用谷歌地圖,並按照以下內容為我的地圖設置最大界限: 谷歌地圖 v3 - 限制可視區域和縮放級別

我的界限設置為:

var strictBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(41.600, -87.857),
  new google.maps.LatLng(42.065, -87.310)
)

在我的dragend事件偵聽器中,我console.log(strictBounds)並得到以下信息:

Google Maps strictBounds 返回

它正在返回我的西南緯度和東北緯度作為一個LatLng和我的西南經度和東北經度作為一個LatLng

我可以稍微破解它並設置西南和東北坐標,以便返回是我想要的樣子,但我想知道為什么在這種情況下會發生這種情況,我是否會與其他人進一步遇到這個問題谷歌地圖方法?

編輯:

只是為了澄清,我在strictBounds設置的兩個LatLng位置應該是地圖最大邊界的southWest 和northEast 位置。

當我使用上面鏈接中提供的addListener方法(Google Maps v3 - 限制可視區域和縮放級別)時,它會從strictBounds錯誤的緯度/經度。

而不是抓取: (41.6, -87.857), (42.065, -87.310)

它抓取: (41.6, 42.065), (-87.31, -87.856999..)

您定義邊界的方式是正確的。 只是不要使用 console.log(strictBounds)。 請改用以下內容

var sw = strictBounds.getSouthWest();
var ne = strictBounds.getNorthEast();

console.log(sw.lat() + "," + sw.lng());
console.log(ne.lat() + "," + ne.lng());

暫無
暫無

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

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