[英]react-places-autocomplete restrictions
I just started using react-places-autocomplete library and I can not find how to restrict predictions to a specified country.我刚开始使用react-places-autocomplete库,但找不到如何将预测限制在特定国家/地区。
I am able to find it for google maps autocomplete ComponentRestrictions but not for the react-places-autocomplete library我能够为谷歌地图自动完成ComponentRestrictions找到它,但不能为react-places-autocomplete库找到它
Is it possible?是否可以?
//just use //只是使用
<PlacesAutocomplete
searchOptions={searchOptions}
//and add a const //并添加一个常量
const searchOptions = {
componentRestrictions: { country: ['us'] },
types: ['city']
}
You can restrict your results with option
prop.您可以使用
option
prop 限制结果。
From docs;来自文档;
options
选项
Type: Object Required: false Default: {}
You can fine-tune the settings passed to the AutocompleteService class with options prop.
您可以使用 options 属性微调传递给 AutocompleteService 类的设置。 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).此道具接受与
google.maps.places.AutocompletionRequest
格式相同的对象(输入除外,它来自输入字段的值)。
// 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}
/>
This is the way to do it, from the docs这是从文档中做到这一点的方法
<GooglePlacesAutocomplete
autocompletionRequest={{
componentRestrictions: {
country: ['us', 'ca'],
}
}}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.