简体   繁体   English

Google Place Autocomplete - 几何边界属性

[英]Google Place Autocomplete - geometry bounds properties

I cannot find this answer in the Google docs so I am posting my question here.我在谷歌文档中找不到这个答案,所以我在这里发布我的问题。

As per the Google Places Autocomplete response docs , bounds is one of the returned fields.根据 Google Places Autocomplete response docsbounds是返回的字段之一。

However, when console logging bounds in the browser, the object has strangely named keys such as Ba , Ab , Ra and so on..但是,当浏览器中的控制台记录bounds时,object 具有奇怪的键名,例如BaAbRa等。

Furthermore, I have noticed that these keys change overtime.此外,我注意到这些键会随着时间的推移而改变。

For example, the following code might fail within a few days.例如,以下代码可能会在几天内失败。 In the initial search for say, New York, bounds.Ab.g may contain a number value.在最初的搜索中,比如 New York, bounds.Ab.g可能包含一个数字值。

however, after a few days bounds.Ab.g might become bounds.Bb.g and the original value will be undefined .但是,几天后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]
    ...

  }

This is an example of the bounds object printed in console.这是在控制台中打印的bounds object 的示例。

    bounds: _.Wf
      Bb: Vf
        g: 49.19817700000001
        h: 49.3172939
      [[Prototype]]: Object
      Ra: Qf
        g: -123.22474
        h: -123.023068

Could anyone point to a doc or explain what these keys stand for and why they keep changing?谁能指出一个文档或解释这些键代表什么以及它们为什么不断变化?

thanks to @geocodezip for the answers in the comments section.感谢@geocodezip 在评论部分提供答案。

I also realized that if I JSON.strigify the result, then the "undocumented" properties are solved to human-readable props.我还意识到,如果我JSON.strigify结果,那么“未记录”的属性将被解析为人类可读的道具。

Strange decision by Google indeed.谷歌确实做出了奇怪的决定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM