简体   繁体   English

react-places-autocomplete 限制

[英]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.

相关问题 使用 react-places-autocomplete 反应最终形式 - React Final Form with react-places-autocomplete Formik 验证不适用于我的自定义 react-places-autocomplete 组件 - Formik validation not working for my custom react-places-autocomplete component 如何使用 react-places-autocomplete 获取邮政编码 - how to get postal code with react-places-autocomplete react-places-autocomplete 下推其他组件 - react-places-autocomplete pushing down the other components below 使用 react-places-autocomplete package 获取邮政编码 - Get Postal Code with react-places-autocomplete package react-places-autocomplete —使用自动完成时如何设置三个输入的状态? - React-places-autocomplete — How can i set state for three inputs whenusing autocompleted? 只希望城市和相关国家使用react-places-autocomplete建议 - Only want cities and related countries in suggestion using react-places-autocomplete google react-places-autocomplete api 将搜索建议限制在澳大利亚/单个国家/地区 - google react-places-autocomplete api restrict search suggestions to Australia / single country 使用 react-google-maps 和 react-places-autocomplete 时出现“Google Maps JavaScript API 多次”错误 - "Google Maps JavaScript API multiple times" error when using react-google-maps with react-places-autocomplete 反应地点自动完成句柄更改错误 - React Places Autocomplete handleChange error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM