ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
473 stars 114 forks source link

Getting UTC offset from place object #144

Closed tylermaran closed 2 years ago

tylermaran commented 2 years ago

I need to pull timezone info from the location. I see the utc_offset property but it is coming back undefined.

image

tylermaran commented 2 years ago

Sorry for the short lived issue. Turns out it was a change in the Google API fields (utc_offset => utc_offset_minutes)

Solution:

  const { ref } = usePlacesWidget({
    apiKey: process.env.GOOGLE_API_KEY,
    onPlaceSelected: place => {
      handleChangeInput(place.formatted_address);
    },
    options: {
      fields: ['address_components', 'formatted_address', 'utc_offset_minutes'],
    },
  });