I'm in the process of developing an application that utilizes the Google Places autocomplete API. However, I specifically want to restrict user input to only residential addresses, excluding businesses and points of interest. Despite going through the documentation, I haven't found a straightforward solution for this. While I know it's possible to limit the autocomplete results to only show businesses, that doesn't suit my requirements. Any guidance on how to achieve this would be greatly appreciated!
Within my next.js app, I am using the react-places-autocomplete
package to implement this feature. If there's a way to modify the search options to enforce this restriction, it would be extremely helpful.
<PlacesAutocomplete
value={searchValue}
onChange={handleChange}
searchOptions={{ componentRestrictions: { country: 'uk' } }}
debounce={500}
>
{({ getInputProps, suggestions, loading }) => (
<Autocomplete
disablePortal
blurOnSelect
loading={loading}
loadingText='Loading...'
options={suggestions.map((x) => x.description)}
sx={{ width }}
onChange={handleOnSelect}
value={address}
renderInput={(params) => <TextField {...getInputProps({ placeholder: 'Address...' })} {...params} label="Search Address" />}
/>
)}
</PlacesAutocomplete>