【发布时间】:2021-11-23 04:00:18
【问题描述】:
我在 Google 文档中找不到这个答案,所以我在这里发布我的问题。
根据 Google 地方信息自动填充响应 docs,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
谁能指出一个文档或解释这些键代表什么以及它们为什么不断变化?
【问题讨论】:
-
这些是
LatLngBounds对象的未记录属性。不应使用它们,请使用 documented 方法来访问您需要的信息。
标签: google-maps google-places-api google-geocoder googleplacesautocomplete