ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
476 stars 113 forks source link

Even though options.strictBounds is set to true, the autocomplete results still return addresses outside of the bounds #121

Closed aamirki closed 3 years ago

aamirki commented 3 years ago

Simplified version of what I did:

const bounds = {
  north: 42.41807720282508
  south: 42.28826258022754,
  east: -70.97969564699982,
  west: -71.1869808579835,
};
return (
  <Autocomplete
    apiKey={...}
    onPlaceSelected={(selected) => onChange(selected)}
    options={{
      bounds,
      strictBounds: true,
      types: ['address'],
      fields: ['formatted_address', 'geometry.location'],
    }}
  />
);

There don't seem to be any errors in the console or generally visible. The results that get suggested are definitely biased towards addresses within the bounds, but they do not filter out addresses outside of the bounds as strictBounds should. The bounds contain just the Boston area but I am getting autocomplete suggestions in Germany, for example.

ErrorPro commented 3 years ago

@aamirki Hey, I'll take some time soon and check this

aamirki commented 3 years ago

Hi after some more fiddling I realize this is actually the same issue as https://github.com/ErrorPro/react-google-autocomplete/issues/77. Setting a new key for the component after my bounds prop changed fixes the issue and makes it work as expected.