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

如何配置Google Maps自动补全仅返回迪拜城市地址?

如何让Google Maps自动补全仅返回迪拜地址

当然可以实现!你之前的配置问题在于bounds默认只是优先推荐边界内的结果,而非强制过滤,再加上只限制了国家级别,所以才会出现阿布扎比的地点。下面给你两种靠谱的解决方案:

方案1:启用严格边界限制 + 精准迪拜范围

通过开启strictBounds: true,让Autocomplete严格只返回你设定的边界内的结果,同时调整经纬度范围覆盖整个迪拜酋长国:

// 覆盖整个迪拜酋长国的精准边界
var defaultBounds = new google.maps.LatLngBounds(
  new google.maps.LatLng(24.8607, 54.9677), // 西南角坐标
  new google.maps.LatLng(25.3894, 55.6088)  // 东北角坐标
);

var options = {
  bounds: defaultBounds,
  strictBounds: true, // 关键:强制过滤边界外的结果
  types: ['establishment'],
  componentRestrictions: { country: 'AE' }
};

var autocomplete = new google.maps.places.Autocomplete(input, options);

方案2:直接指定迪拜行政区域

迪拜是阿联酋的一级行政区域(酋长国),可以通过componentRestrictions直接限制到该区域,无需设置边界:

var options = {
  types: ['establishment'],
  componentRestrictions: { 
    country: 'AE',
    administrativeArea: 'Dubai' // 精准限制到迪拜行政区域
  }
};

var autocomplete = new google.maps.places.Autocomplete(input, options);

额外优化提示

  • 建议两种方案结合使用,同时设置componentRestrictions和strictBounds,双重过滤确保结果100%来自迪拜。
  • 如果需要普通住宅地址而非商业场所,可以把types: ['establishment']改成types: ['address'],或者直接移除types字段(返回所有类型的地址结果)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:01:58