【问题标题】:Google place autocomplete address from one country only [duplicate]Google仅来自一个国家/地区的自动填充地址[重复]
【发布时间】:2021-10-29 11:20:11
【问题描述】:

我正在使用 Google Autocomplete Place API,使用以下代码可以正常工作。

autocompleteform = new google.maps.places.Autocomplete(
             (document.getElementById('autocomplete')),
                {}
            );

现在的问题是它会自动建议来自全世界的地址。 我想展示一个特定国家的结果,比如说瑞士,怎么做?

【问题讨论】:

标签: google-places-api google-places


【解决方案1】:

我自己使用 API 文档和示例解决了这个问题。 这是我添加的代码行。

/* Restrict to switzerland only */
 autocompleteform.setComponentRestrictions(
     {
         'country': ['CH']
      }
 );

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 2020-05-20
    • 1970-01-01
    • 2018-03-30
    • 2017-12-11
    • 2016-03-14
    • 1970-01-01
    • 2017-10-20
    • 2011-05-02
    相关资源
    最近更新 更多