Home > Software design >  Google Place Autocomplete - geometry bounds properties
Google Place Autocomplete - geometry bounds properties

Time:11-26

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.

However, when console logging bounds in the browser, the object has strangely named keys such as Ba, Ab, Ra and so on..

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.

however, after a few days bounds.Ab.g might become bounds.Bb.g and the original value will be 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: _.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?

CodePudding user response:

thanks to @geocodezip for the answers in the comments section.

here is the solution

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

Strange decision by Google indeed.

  • Related