【问题标题】:Google Place Autocomplete - geometry bounds propertiesGoogle Place Autocomplete - 几何边界属性
【发布时间】:2021-11-23 04:00:18
【问题描述】:

我在 Google 文档中找不到这个答案,所以我在这里发布我的问题。

根据 Google 地方信息自动填充响应 docsbounds 是返回的字段之一。

但是,当控制台在浏览器中记录bounds 时,该对象具有奇怪的命名键,例如BaAbRa 等等..

此外,我注意到这些键会随着时间的推移而变化。

例如,以下代码可能会在几天内失败。在最初的搜索中,比如纽约,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

谁能指出一个文档或解释这些键代表什么以及它们为什么不断变化?

【问题讨论】:

标签: google-maps google-places-api google-geocoder googleplacesautocomplete


【解决方案1】:

感谢@geocodezip 在 cmets 部分的解答。

解决办法

      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()

Google 的决定确实很奇怪。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-15
    • 2020-08-10
    • 2019-03-25
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 2014-01-14
    • 2017-07-25
    相关资源
    最近更新 更多