【问题标题】:Set componentRestrictions with Google Place Autocomplete API使用 Google Place Autocomplete API 设置 componentRestrictions
【发布时间】:2018-08-09 19:14:12
【问题描述】:

我正在制作一个自定义的自动填充字段,我的目标是仅从一个国家/地区获取城市。

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amsterdam&inputtype=textquery&types=(cities)&fields=geometry,name&language=nl&key=APIKEY

我已经阅读了有关绑定特定国家/地区的组件限制。如何在请求中包含参数?

添加参数&componentRestrictions=nl 不起作用。

【问题讨论】:

    标签: google-maps google-places-api googleplacesautocomplete


    【解决方案1】:

    对于 Web 服务,每个 the documentation 的参数是 components

    • 组件 — 您希望将结果限制在其中的一组位置。目前,您可以使用组件过滤多达 5 个国家/地区。国家/地区必须作为两个字符传递,与 ISO 3166-1 Alpha-2 兼容的国家/地区代码。例如: components=country:fr 会将您的结果限制在法国境内。多个国家/地区必须作为多个国家/地区:XX 过滤器传递,管道字符 (|) 作为分隔符。例如:components=country:us|country:pr|country:vi|country:gu|country:mp 会将您的结果限制在美国及其未合并的有组织领土内的地方。

    示例:components=country:nl

    完整网址:

    https://maps.googleapis.com/maps/api/place/autocomplete/json?input=amsterdam&inputtype=textquery&types=(cities)&fields=geometry,name&language=nl&components=country:nl&key=APIKEY
    

    【讨论】:

      猜你喜欢
      • 2018-11-09
      • 2017-08-31
      • 2019-03-25
      • 2014-01-14
      • 2020-08-10
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      相关资源
      最近更新 更多