javascript - 多个国家/地区的 Google Places Autocomplete API 过滤器

标签 javascript google-places-api

寻找一种方法来过滤由 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/

相关文章:

java - 如何使用 Google 地方信息自动完成功能获取位置的完整地址?

ios - 我们如何在 google place IOS API 中传递类型、page_token、排序等?

javascript - Google Places 自动完成和搜索不工作

android - 如何在 Google map Android API v2 中找到沿途的加油站

javascript - 不使用 Javascript 将 CSS 文件加载到 head 部分或 HTML 部分

php - 使用 php 或 javascript 查看它是否为 "my iPad"

javascript - 在带有辅助函数的 ejs 中使用 .then 返回 [ object promise ]

android - 适用于 Android 的 Google Place API : can't select place with the picker of Place Picker

javascript - canvas.toBlob() 仍然无法处理 Chrome ......解决方法?

PHP 数组到 JavaScript