You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置Google Places Autocomplete API仅返回指定国家的地址建议

Google Autocomplete Place API 限定国家返回结果配置方法

要实现仅返回特定国家的地址建议,只需在Autocomplete实例的第二个配置参数中新增componentRestrictions字段,指定对应国家的两位ISO 3166-1编码即可,瑞士对应的编码为CH。

修改后可直接运行的代码

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

额外配置说明

  • 若需要同时限制多个国家,可将country的值改为数组格式,最多支持同时限定5个国家,示例:
    // 同时限定瑞士、法国返回结果
    componentRestrictions: { country: ['CH', 'FR'] }
    
  • 国家代码不区分大小写,符合ISO 3166-1 Alpha-2标准即可。

内容的提问来源于stack exchange,提问作者ishaq

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 18:18:04