我在 Google 檔案中找不到這個答案,所以我在這里發布我的問題。
根據 Google Places Autocomplete 回應檔案,bounds是回傳的欄位之一。
然而,當控制臺記錄bounds在瀏覽器中,物件已經奇怪命名鍵,如Ba,Ab,Ra等..
此外,我注意到這些鍵會隨著時間的推移而改變。
例如,以下代碼可能會在幾天內失敗。在最初的搜索中說,紐約,bounds.Ab.g可能包含一個數字值。
但是,幾天后bounds.Ab.g可能會變成bounds.Bb.g原始值undefined。
import PlacesAutocomplete, { geocodeByAddress } from 'react-places-autocomplete'
const GooglePlacesSearchBar = () => {
const handleSelect = async userInput => {
const result = await geocodeByAddress(userInput)
const { place_id, geometry, formatted_address } = result[0]
const { bounds } = geometry
const swBounds = [bounds.Ab.g, bounds.Ra.g]
const neBounds = [bounds.Ab.h, bounds.Ra.h]
...
}
這是bounds在控制臺中列印的物件的示例。
bounds: _.Wf
Bb: Vf
g: 49.19817700000001
h: 49.3172939
[[Prototype]]: Object
Ra: Qf
g: -123.22474
h: -123.023068
任何人都可以指向檔案或解釋這些鍵代表什么以及它們為什么不斷變化?
uj5u.com熱心網友回復:
感謝@geocodezip 在評論部分提供答案。
這是解決方案
const result = await geocodeByAddress(userInput)
const { geometry } = result[0]
const { bounds } = geometry
const NELat = bounds.getNorthEast().lat()
const NELng = bounds.getNorthEast().lng()
const SWLat = bounds.getSouthWest().lat()
const SWLng = bounds.getSouthWest().lng()
谷歌確實做出了奇怪的決定。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/368324.html
標籤:谷歌地图 google-places-api 谷歌地理编码器 谷歌地方自动完成
下一篇:致命錯誤com.google.firebase.database.DatabaseException:無法將java.lang.String型別的值轉換為long
