网淘吧来吧,欢迎您!

调用百度地图api功能

2026-03-29 新闻来源:网淘吧 围观:4
电脑广告
手机广告

百度地图 (Baidu Map)

本技能使用百度地图 Web 服务 API 提供丰富的地理位置服务。

重要:使用本技能前,你必须在百度地图开放平台申请一个应用,并获取 Access Key (AK),然后将其设置为环境变量BAIDU_MAP_AK

调用百度地图api功能

export BAIDU_MAP_AK="你的百度地图Access Key"

Clawdbot 会自动读取这个环境变量来调用 API。

何时使用 (触发条件)

当用户提出以下类型的请求时,应优先使用本技能:

  • "帮我查一下[城市]的天气"
  • "搜索[地点]附近的[东西]"
  • "查找[关键词]的位置"
  • "从[A]到[B]怎么走?"
  • "查询[地址]的经纬度"
  • "这个坐标[经度,纬度]是哪里?"
  • "百度地图[地点]"

核心功能与用法

1. 地点搜索 (POI检索)

用于根据关键字在指定区域搜索地点信息。

# 将 [关键词] 替换为用户提供的内容
# region参数可以是城市名或区域名
curl "https://api.map.baidu.com/place/v2/search?query=[关键词]&region=全国&output=json&ak=$BAIDU_MAP_AK"

# 或者指定具体城市
curl "https://api.map.baidu.com/place/v2/search?query=[关键词]&region=广州&output=json&ak=$BAIDU_MAP_AK"

2. 城市内地点搜索

用于在特定城市内搜索地点,结果更精确。

# 将 [关键词] 和 [城市] 替换为实际内容
curl "https://api.map.baidu.com/place/v2/search?query=[关键词]&region=[城市]&output=json&ak=$BAIDU_MAP_AK"

3. 周边搜索 (圆形区域内搜索)

用于在指定坐标点周围搜索特定类型的地点。

# 将 [经度,纬度] 替换为实际坐标,radius为搜索半径(米)
curl "https://api.map.baidu.com/place/v2/search?query=花店&location=[纬度],[经度]&radius=1000&output=json&ak=$BAIDU_MAP_AK"

4. 地理编码 (地址 → 坐标)

Convert structured address information into latitude and longitude coordinates.

# 将 [地址] 替换为用户提供的地址
curl "https://api.map.baidu.com/geocoding/v3/?address=[地址]&output=json&ak=$BAIDU_MAP_AK"

5. Reverse Geocoding (Coordinates → Address)

Convert latitude and longitude coordinates into structured address information.

# 将 [经度,纬度] 替换为实际坐标
curl "https://api.map.baidu.com/reverse_geocoding/v3/?coordtype=wgs84ll&location=[纬度],[经度]&output=json&ak=$BAIDU_MAP_AK"

6. Driving Route Planning

Used to plan driving routes between two locations.

# 将 [起点] 和 [终点] 替换为实际地址或坐标
# 起终点可以用地址表示,也可以用经纬度表示
curl "https://api.map.baidu.com/direction/v2/driving?origin=[起点]&destination=[终点]&output=json&ak=$BAIDU_MAP_AK"

# 使用经纬度坐标的示例
curl "https://api.map.baidu.com/direction/v2/driving?origin=39.90923,116.397428&destination=31.230416,121.473701&output=json&ak=$BAIDU_MAP_AK"

7. Walking Route Planning

Used to plan walking routes between two locations.

# 将 [起点] 和 [终点] 替换为实际地址或坐标
curl "https://api.map.baidu.com/direction/v2/walking?origin=[起点]&destination=[终点]&output=json&ak=$BAIDU_MAP_AK"

8. Public Transit Route Planning

Used to plan public transit routes between two locations.

# 将 [起点] 和 [终点] 替换为实际地址或坐标
curl "https://api.map.baidu.com/direction/v2/transit?origin=[起点]&destination=[终点]&output=json&ak=$BAIDU_MAP_AK"

9. Administrative Division Boundary Query

Used to query the boundary coordinate point collection of administrative regions.

# 将 [行政区名称] 替换为实际的省市区名称
curl "https://api.map.baidu.com/district/v1/getdistrict?qt=dis&level=city&names=[行政区名称]&ak=$BAIDU_MAP_AK"

10. IP Location

Obtain approximate geographic location information based on an IP address.

# 将 [IP地址] 替换为实际IP,若不提供则使用当前客户端IP
curl "https://api.map.baidu.com/location/ip?ip=[IP地址]&ak=$BAIDU_MAP_AK"

Usage Tips

  1. Search Radius: When performing nearby searches, you can adjust the radius parameter as needed. The default is 1000 meters.
  2. Coordinate System: Baidu Maps primarily uses the BD09 coordinate system. Pay attention to conversions with other coordinate systems.
  3. Result Count: By default, 10 results are returned. This can be adjusted via the page_size parameter (maximum 50).
  4. Pagination Query: When there are many results, you can use the page_num parameter to retrieve results from subsequent pages.

Error Handling

If the API returns an error, it is usually due to one of the following reasons:

  • The AK is invalid or not set correctly.
  • 请求参数格式错误
  • API调用次数超限
  • 网络连接问题

免责申明
部分文章来自各大搜索引擎,如有侵权,请与我联系删除。
打赏
文章底部电脑广告
手机广告位-内容正文底部

相关文章

您是本站第326368名访客 今日有221篇新文章/评论