ErrorPro / react-google-autocomplete

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

Want to get auto Complete when I switch countries #155

Closed pointline closed 1 year ago

pointline commented 2 years ago

Thanks a lot, great project

<Autocomplete
  apiKey={YOUR_GOOGLE_MAPS_API_KEY}
  style={{ width: "90%" }}
  onPlaceSelected={(place) => {
    console.log(place);
  }}
  options={{
    types: ["(regions)"],
    componentRestrictions: { country: "us" },
  }}
  defaultValue="Amsterdam"
/>;

Modified country parameters

<Autocomplete
  apiKey={YOUR_GOOGLE_MAPS_API_KEY}
  style={{ width: "90%" }}
  onPlaceSelected={(place) => {
    console.log(place);
  }}
  options={{
    types: ["(regions)"],
    componentRestrictions: { country: "gb" },
  }}
  defaultValue="Amsterdam"
/>;

Switch from us to gb, but the data obtained is still us

menashkes commented 2 years ago

Hey

I'm also updating the options prop and the autocomplete is not responding to that. I believe there is a need to recreate the component registration to google but I'm not sure how.

Please advise

Thanks

AlexeyRDKV commented 1 year ago

Everything works, check if you accidentally use google api key with already set region in html. <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

Screenshot 2022-12-09 at 19 41 23 Screenshot 2022-12-09 at 19 42 04