Reputation: 315
I just started using react-places-autocomplete library and I can not find how to restrict predictions to a specified country.
I am able to find it for google maps autocomplete ComponentRestrictions but not for the react-places-autocomplete library
Is it possible?
Upvotes: 1
Views: 8819
Reputation: 1
<Autocomplete
options={{
types: ["(regions)"],
componentRestrictions: { country: "ru" },
}}
/>
Upvotes: 0
Reputation: 2204
This is the way to do it, from the docs
<GooglePlacesAutocomplete
autocompletionRequest={{
componentRestrictions: {
country: ['us', 'ca'],
}
}}
/>
Upvotes: 0
Reputation: 307
//just use
<PlacesAutocomplete
searchOptions={searchOptions}
//and add a const
const searchOptions = {
componentRestrictions: { country: ['us'] },
types: ['city']
}
Upvotes: 12
Reputation: 24660
You can restrict your results with option
prop.
From docs;
options
Type: Object Required: false Default: {}
You can fine-tune the settings passed to the AutocompleteService class with options prop. This prop accepts an object following the same format as
google.maps.places.AutocompletionRequest
(except for input, which comes from the value of the input field).
// these options will bias the autocomplete predictions toward Sydney, Australia with a radius of 2000 meters,
// and limit the results to addresses only
const options = {
location: new google.maps.LatLng(-34, 151),
radius: 2000,
types: ['address']
}
<PlacesAutocomplete
inputProps={inputProps}
options={options}
/>
Upvotes: 3