寻找一种方法来过滤由 2 个国家(加拿大和美国)过滤的自动完成结果。
目前我只能通过这样的选项过滤一个或另一个......
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'us'}
}
var autocomplete = new google.maps.places.Autocomplete(input,options);
...但我还没有看到任何说明如何将自动完成结果限制在 2 个国家/地区的文档。
感谢任何帮助。
最佳答案
Google Places API 目前不支持此功能。如果您认为这是一个有用的功能,您可以提交“Places API - 功能请求”here .
更新
此功能于 2017 年 1 月在 Maps JavaScript API 3.27 版中引入:
You can now restrict Autocomplete predictions to only surface from multiple countries. You can do this by specifying up to 5 countries in the componentRestrictions field of the AutocompleteOptions.
https://developers.google.com/maps/documentation/javascript/releases https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions
关于javascript - 多个国家/地区的 Google Places Autocomplete API 过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11047408/