react-places-自动完成限制

问题描述 投票:0回答:4

我刚刚开始使用 react-places-autocomplete 库,我找不到如何将预测限制到指定的国家/地区。

我可以为谷歌地图自动完成ComponentRestrictions找到它,但不能为react-places-autocomplete库找到它

可以吗?

reactjs google-maps autocomplete
4个回答
11
投票

//只需使用

 <PlacesAutocomplete
    searchOptions={searchOptions}

//并添加一个const

const searchOptions = {
  componentRestrictions: { country: ['us'] },
  types: ['city']
}

3
投票

您可以使用

option
属性限制结果。

来自文档;

选项

Type: Object Required: false Default: {}

您可以微调传递给 AutocompleteService 类的设置 与选项道具。这个 prop 接受一个遵循相同的对象 格式为

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}
/>

0
投票

这是文档中的方法

<GooglePlacesAutocomplete
  autocompletionRequest={{
    componentRestrictions: {
      country: ['us', 'ca'],
    }
  }}
/>

0
投票
<Autocomplete
 options={{
    types: ["(regions)"],
    componentRestrictions: { country: "ru" },
  }}
/>
© www.soinside.com 2019 - 2024. All rights reserved.