javascript - 如何将谷歌自动完成地点限制为N个国家?

标签 javascript google-maps google-places-api google-places

我知道可以将地点限制在 1 个国家/地区:

componentRestrictions: {country: "fr"}

但是有没有办法限制像[“fr”,“be”]这样的N个国家?

最佳答案

componentRestrictions 实际上最多可以处理 5 个国家/地区,只需将国家/地区代码附加到具有 5 个元素的数组即可。

    { country: ["ch","at","fr","gr","mx"] }

Google 本身表示:“-componentRestrictions 可用于将结果限制为特定组。目前,您可以使用 componentRestrictions 过滤最多 5 个国家/地区。国家/地区必须作为两个字符、ISO 3166-1 Alpha-2 兼容的国家/地区代码传递。多个国家/地区必须作为国家/地区代码列表传递。 (查找:https://developers.google.com/maps/documentation/javascript/places-autocomplete)

Note: Question was already answered here: Need multiple country componentRestrictions in Google Places Autocomplete

关于javascript - 如何将谷歌自动完成地点限制为N个国家?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58889122/

相关文章:

javascript - 在框架窗口的上下文中运行代码

google-maps - PlacesService和html节点的需要

javascript - Google Places 自动完成 - 在 Enter 键上选择第一个结果?

javascript - 单击元素时将元素 ID 传递给 js 函数

javascript - Shiny :如何正确包含 Shiny 的 HTML

*NgIf 完成后 Angular 4 运行代码

javascript - 离开页面后返回谷歌地图 V3 上的标记

android - 如何在 onCreateView() 中调用 SupportPlaceAutocompleteFragment

javascript - 选择 html 元素 1,2,5,6 ...元素数量未知的优雅方法/

android - 如何在具有缩放状态的android中重置谷歌地图