react-google-autocomplete icon indicating copy to clipboard operation
react-google-autocomplete copied to clipboard

Want to get auto Complete when I switch countries

Open pointline opened this issue 3 years ago • 1 comments

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

pointline avatar Mar 18 '22 03:03 pointline

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

menashkes avatar Aug 29 '22 03:08 menashkes

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

AlexeyRDKV avatar Dec 09 '22 12:12 AlexeyRDKV