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

如何借助地图API获取指定半径范围内的周边sublocalities?

获取指定半径内周边Sublocalities的地图API实现方法

我之前也碰到过类似的需求,刚好整理过Google和Bing Maps API的具体实现方式,给你一步步拆解:

Google Maps API 实现步骤

Google这边主要用Places API的Nearby Search接口,专门用来获取指定区域内的地点类型数据,直接定位sublocality很方便:

  1. 构造请求参数
    核心参数必须包含:

    • location: 目标经纬度,格式为纬度,经度
    • radius: 搜索半径(单位:米)
    • type: 固定设为sublocality(或者更细分的sublocality_level_1,根据你需要的行政级别调整)
    • key: 你的Google Maps API密钥

    示例请求:

    https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.7749,-122.4194&radius=5000&type=sublocality&key=YOUR_API_KEY
    
  2. 筛选有效数据
    返回的JSON结果里,results数组中的每个条目都是符合条件的sublocality,你可以提取这些核心字段:

    • name: 子区域名称
    • geometry.location.lat/lng: 子区域的中心点经纬度
    • types: 确认是否包含sublocality(防止返回其他类型的地点)

    比如用JavaScript解析的参考逻辑:

    const response = await fetch(上述请求URL);
    const data = await response.json();
    const validSublocalities = data.results.filter(place => place.types.includes('sublocality'));
    

Bing Maps API 实现步骤

Bing Maps用Search API的Nearby Search接口,需要指定实体类型为sublocality:

  1. 构造请求参数
    核心参数:

    • centerPoint: 目标经纬度,格式为纬度,经度
    • radius: 搜索半径(单位:米)
    • entityType: 固定设为Sublocality
    • key: 你的Bing Maps API密钥

    示例请求:

    https://dev.virtualearth.net/REST/v1/Search/Nearby?centerPoint=37.7749,-122.4194&radius=5000&entityType=Sublocality&key=YOUR_API_KEY
    
  2. 提取有用信息
    返回的JSON结果中,resourceSets[0].resources数组里的条目就是目标sublocality,重点提取:

    • name: 子区域名称
    • point.coordinates: 子区域的经纬度数组([纬度, 经度])
    • entityType: 确认是Sublocality

    示例解析逻辑:

    const response = await fetch(上述请求URL);
    const data = await response.json();
    const sublocalities = data.resourceSets[0].resources.filter(item => item.entityType === 'Sublocality');
    

额外注意事项

  • 两个API都有请求配额限制,记得在控制台查看你的使用额度,避免超出限制
  • 如果搜索半径较大,返回结果可能分页:Google的Nearby Search需要用pagetoken参数翻页,Bing则用skip参数
  • 部分区域的sublocality划分可能比较细,可根据需求调整type(Google)或entityType(Bing)的细分级别

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:20:02