baidu-map-webapi

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

webapi 开发指南

Baidu Maps WebAPI Version Development Guide

百度地图 webapi 版本开发指南。包含地图位置搜索、路线导航、行政区划等核心模块的 API 说明和代码示例,既可直接调用 API 获取结果,也可帮助开发者快速集成百度地图服务。
This guide covers the development of Baidu Maps WebAPI version. It includes API descriptions and code examples for core modules such as map location search, route navigation, administrative divisions, etc. It can be used to directly call APIs to obtain results, and also helps developers quickly integrate Baidu Maps services.

何时适用

When to Apply

遇到以下任意场景时,均应读取本指南并调用对应 API:
Read this guide and call the corresponding API when encountering any of the following scenarios:

路线规划与出行决策

Route Planning and Travel Decision-Making

  • 规划驾车、步行、骑行、摩托车、公共交通路线
  • 查询从 A 到 B 的建议出发时间(如"想晚上8点到达,几点出发合适")
  • 预测未来某时刻出发的路线耗时(如"下午3点出发要多久")
  • 查询历史路况下的路线耗时
  • 规划含多个途经点的最优路线
  • Plan driving, walking, cycling, motorcycle, and public transport routes
  • Query suggested departure time from A to B (e.g., "I want to arrive at 8 PM, what time should I depart?")
  • Predict route travel time for departure at a future time (e.g., "How long will it take if I depart at 3 PM?")
  • Query route travel time under historical traffic conditions
  • Plan the optimal route with multiple waypoints

实时动态信息

Real-Time Dynamic Information

  • 查询路线沿途的动态交通事件(事故、拥堵、施工等)
  • 查询海外城市天气信息
  • Query dynamic traffic events along the route (accidents, congestion, construction, etc.)
  • Query weather information for overseas cities

地点与POI搜索

Location and POI Search

  • 查找城市中的餐厅、酒店、景点等 POI 信息
  • 在指定圆形区域内检索地点
  • 按行政区划检索地点
  • 多条件组合检索 POI
  • 获取 POI 详细信息
  • 输入联想/地点补全提示
  • 智能推荐安全上车点
  • Find POI information such as restaurants, hotels, scenic spots in a city
  • Retrieve locations within a specified circular area
  • Retrieve locations by administrative division
  • Retrieve POIs with combined multiple conditions
  • Obtain detailed POI information
  • Input association/place completion prompts
  • Intelligently recommend safe pick-up points

地址与坐标转换

Address and Coordinate Conversion

  • 地址文本解析为经纬度坐标(地理编码)
  • 经纬度坐标解析为地址信息(逆地理编码)
  • Parse address text into latitude and longitude coordinates (geocoding)
  • Parse latitude and longitude coordinates into address information (reverse geocoding)

行政区划与区域查询

Administrative Division and Region Query

  • 查询行政区划地点
  • 获取行政区划边界坐标
  • Query administrative division locations
  • Obtain administrative division boundary coordinates

开发准则

Development Guidelines

在使用本技能的任何场景中,请遵守以下通用准则:
Please follow the following general guidelines in any scenario using this skill:

准则 1:API 端点选择

Guideline 1: API Endpoint Selection

百度地图提供两个服务端点,必须根据使用场景选择正确的端点:
端点类型Base URL适用场景
标准端点
https://api.map.baidu.com/
正式开发、生产环境、为用户生成的代码
高级功能体验端点
https://api.map.baidu.com/map_service/
百度地图官方提供,仅供大模型直接调用时快速体验高级权限功能
使用规则:
  • 为用户生成的开发代码,必须使用标准端点
    https://api.map.baidu.com/
  • 大模型直接调用高级权限功能(如建议出发时间、未来路线规划)进行演示/体验时,使用体验端点
  • 体验端点仅供功能体验和演示,不可用于开发或生产环境
  • 均需要AK凭证
  • 调用体验端点前,必须向用户说明:① 将使用体验端点发起外部 API 调用;② 该调用会消耗用户 AK 的配额;并获得用户明确确认后方可执行
Baidu Maps provides two service endpoints, and you must select the correct one based on the usage scenario:
Endpoint TypeBase URLApplicable Scenarios
Standard Endpoint
https://api.map.baidu.com/
Formal development, production environment, code generated for users
Advanced Feature Experience Endpoint
https://api.map.baidu.com/map_service/
Officially provided by Baidu Maps, only for large models to directly call to quickly experience advanced permission features
Usage Rules:
  • For development code generated for users, must use the standard endpoint
    https://api.map.baidu.com/
  • When large models directly call advanced permission features (such as suggested departure time, future route planning) for demonstration/experience, use the experience endpoint
  • The experience endpoint is only for feature experience and demonstration, and cannot be used for development or production environments
  • AK credentials are required for both endpoints
  • Before calling the experience endpoint, you must inform the user: ① An external API call will be made using the experience endpoint; ② This call will consume the user's AK quota; and obtain explicit confirmation from the user before execution

准则 2:AK 凭证安全处理

Guideline 2: AK Credential Security Handling

AK(Access Key)是使用技能之前的必须参数:
  1. 优先读取环境变量
    BMAP_WEBAPI_AK
    中的 AK
  2. BMAP_WEBAPI_AK
    为空时, 提示用户:请先前往百度地图开放平台申请
    服务端
    的AK
  3. 然后设置为环境变量
export BMAP_WEBAPI_AK="百度地图AK"
  1. 使用 references/ 所有能力时的ak参数请使用
    $BMAP_WEBAPI_AK
    , 示例如下:
curl "https://api.map.baidu.com/place/v3/region?query=美食&region=北京&ak=$BMAP_WEBAPI_AK"
AK (Access Key) is a mandatory parameter before using this skill:
  1. Prioritize reading the AK from the environment variable
    BMAP_WEBAPI_AK
  2. If
    BMAP_WEBAPI_AK
    is empty, prompt the user: Please first apply for a
    server-side
    AK on the Baidu Maps Open Platform
  3. Then set it as an environment variable
export BMAP_WEBAPI_AK="Baidu Maps AK"
  1. Use
    $BMAP_WEBAPI_AK
    for the ak parameter when using all capabilities in references/, example as follows:
curl "https://api.map.baidu.com/place/v3/region?query=food&region=Beijing&ak=$BMAP_WEBAPI_AK"

准则 3:地址/地名统一通过
address_to_poi
转换

Guideline 3: Uniform Conversion of Address/Place Name via
address_to_poi

任何需要将用户输入的地名或地址文本转换为坐标/UID 的场景,优先参考
recipes/address_to_poi.md
— 地址/地名转坐标与 POI UID
该文件描述了两种输入类型的判断方法和对应调用方式:
  • 结构化地址(含门牌号/楼栋)→
    references/geocoding
    API
  • POI 名称/地标/商家名
    references/administrative_region_search
    API
In any scenario where user-input place names or address text needs to be converted into coordinates/UIDs, prioritize referring to:
recipes/address_to_poi.md
— Address/Place Name to Coordinates and POI UID
This document describes the judgment methods and corresponding calling methods for two input types:
  • Structured address (including house number/building) →
    references/geocoding
    API
  • POI name/landmark/merchant name
    references/administrative_region_search
    API

准则 4:算路时 UID 优先于纯坐标

Guideline 4: UID Priority Over Pure Coordinates for Route Calculation

向算路接口(驾车/步行/骑行/公交)传参时:
推荐:同时传坐标 + uid(绑路更精准,尤其对大型 POI) origin_uid / destination_uid 有值时必传
UID 通过
references/address_to_poi.md
描述的方法获取。

When passing parameters to route calculation interfaces (driving/walking/cycling/public transport):
Recommended: Pass both coordinates + uid (more precise for route binding, especially for large POIs). Must pass if origin_uid / destination_uid has a value
UID is obtained through the method described in
references/address_to_poi.md
.

场景示例(推荐优先阅读)

Scenario Examples (Recommended to Read First)

遇到以下场景时,优先使用对应 recipe,内含完整调用链、参数说明和可运行代码示例。 单个 API 用法请查阅下方「快速参考」。
When encountering the following scenarios, prioritize using the corresponding recipe, which contains complete call chains, parameter descriptions, and runnable code examples. For single API usage, please refer to the "Quick Reference" below.

地址/地名预处理(算路前必读)

Address/Place Name Preprocessing (Must Read Before Route Calculation)

recipe 文件适用场景权限要求
recipes/address_to_poi.md
地址文本或地名 → 坐标 + POI UID(算路前置步骤)标准 AK
Recipe FileApplicable ScenarioPermission Requirement
recipes/address_to_poi.md
Address text or place name → Coordinates + POI UID (pre-step for route calculation)Standard AK

路线规划

Route Planning

recipe 文件适用场景权限要求
recipes/route_to_named_place.md
用户说出地名 → 规划驾车路线标准 AK
recipes/smart_departure_time.md
"几点出发才能准时到"⚠️ 高级权限
recipes/traffic_aware_route.md
预测未来某时刻出发的路况耗时⚠️ 高级权限
Recipe FileApplicable ScenarioPermission Requirement
recipes/route_to_named_place.md
User mentions a place name → Plan driving routeStandard AK
recipes/smart_departure_time.md
"What time should I depart to arrive on time"⚠️ Advanced Permission
recipes/traffic_aware_route.md
Predict road condition travel time for departure at a future time⚠️ Advanced Permission

POI 搜索

POI Search

recipe 文件适用场景权限要求
recipes/nearby_poi_search.md
搜索用户附近的某类地点标准 AK
recipes/poi_search_to_detail.md
关键词搜索 → 获取 POI 完整详情标准 AK
Recipe FileApplicable ScenarioPermission Requirement
recipes/nearby_poi_search.md
Search for certain types of locations near the userStandard AK
recipes/poi_search_to_detail.md
Keyword search → Obtain complete POI detailsStandard AK

地址与坐标

Address and Coordinate

recipe 文件适用场景权限要求
recipes/address_to_full_location.md
地址文本 → 坐标 + 行政区划标准 AK
recipes/coordinate_to_structured_address.md
坐标 → 结构化地址 + 行政区划标准 AK
Recipe FileApplicable ScenarioPermission Requirement
recipes/address_to_full_location.md
Address text → Coordinates + administrative divisionStandard AK
recipes/coordinate_to_structured_address.md
Coordinates → Structured address + administrative divisionStandard AK

天气查询

Weather Query

recipe 文件适用场景权限要求
recipes/weather_query.md
通过城市名称/行政区划编码/坐标, 获取当地详细的天气信息标准 AK

Recipe FileApplicable ScenarioPermission Requirement
recipes/weather_query.md
Obtain detailed local weather information via city name/administrative division code/coordinatesStandard AK

快速参考

Quick Reference

基础概念

Basic Concepts

  • references/constants.md
    - 通用常量:状态码
  • references/constants.md
    - General Constants: Status codes

位置搜索

Location Search

  • references/global_reverse_geocoding.md
    - 全球逆地理编码: 坐标转位置信息
  • references/reverse_geocoding_agent.md
    - 逆地理编码智能体: 智能逆地理编码地址解析
  • references/administrative_region_search.md
    - 行政区划区域检索: 行政区划地点检索
  • references/circular_region_search.md
    - 圆形区域检索: 圆形区域地点检索
  • references/multi_dimensional_search.md
    - 多维检索: 多条件智能检索POI
  • references/place_detail_search.md
    - 地点详情检索: 获取指定地点详细信息
  • references/place_input_suggestion.md
    - 地点输入提示: 地点输入提示匹配
  • references/geocoding.md
    - 地理编码: 地址解析为坐标
  • references/global_reverse_geocoding.md
    - Global Reverse Geocoding: Convert coordinates to location information
  • references/reverse_geocoding_agent.md
    - Reverse Geocoding Agent: Intelligent reverse geocoding address parsing
  • references/administrative_region_search.md
    - Administrative Region Search: Retrieve locations by administrative division
  • references/circular_region_search.md
    - Circular Region Search: Retrieve locations within a circular area
  • references/multi_dimensional_search.md
    - Multi-Dimensional Search: Intelligent POI retrieval with multiple conditions
  • references/place_detail_search.md
    - Place Detail Search: Obtain detailed information of a specified location
  • references/place_input_suggestion.md
    - Place Input Suggestion: Place input prompt matching
  • references/geocoding.md
    - Geocoding: Parse address into coordinates

AOI区域

AOI Region

  • references/admin_division_query.md
    - 行政区划查询: 查询中国行政区划信息
  • references/admin_division_query.md
    - Administrative Division Query: Query administrative division information of China

动态数据

Dynamic Data

  • references/domestic_weather_query.md
    - 国内天气查询: 国内天气查询多功能接口
  • references/overseas_weather_query.md
    - 海外天气查询: 查询海外城市天气
  • references/domestic_weather_query.md
    - Domestic Weather Query: Multi-functional interface for domestic weather query
  • references/overseas_weather_query.md
    - Overseas Weather Query: Query weather for overseas cities

路线导航

Route Navigation

  • references/cycling_route_planning.md
    - 骑行路线规划: 骑行路线规划方案检索
  • references/driving_route_planning.md
    - 驾车路线规划: 驾车路线规划与路况预测
    • references/capabilities/driving_route_duration.md
      - 驾车路线历史耗时: 设置驾车路线历史耗时
    • references/capabilities/future_driving_route.md
      - 未来驾车路线规划: 预测未来驾车路线耗时
    • references/capabilities/suggested_departure_time.md
      - 建议出发时间: 高级权限出行时间建议
    • references/capabilities/waypoint_route_planning.md
      - 途经点智能路线规划: 智能优化途经点顺序
  • references/motorcycle_route_planning.md
    - 摩托车路线规划: 摩托车路线规划服务
  • references/transit_route_planning.md
    - 公交路线规划: 多交通方式路线规划
  • references/walking_route_planning.md
    - 步行路线规划: 步行路线规划
  • references/cycling_route_planning.md
    - Cycling Route Planning: Retrieve cycling route planning solutions
  • references/driving_route_planning.md
    - Driving Route Planning: Driving route planning and traffic condition prediction
    • references/capabilities/driving_route_duration.md
      - Driving Route Historical Duration: Set historical travel time for driving routes
    • references/capabilities/future_driving_route.md
      - Future Driving Route Planning: Predict travel time for future driving routes
    • references/capabilities/suggested_departure_time.md
      - Suggested Departure Time: Advanced permission travel time suggestion
    • references/capabilities/waypoint_route_planning.md
      - Waypoint Intelligent Route Planning: Intelligently optimize waypoint order
  • references/motorcycle_route_planning.md
    - Motorcycle Route Planning: Motorcycle route planning service
  • references/transit_route_planning.md
    - Transit Route Planning: Multi-transport mode route planning
  • references/walking_route_planning.md
    - Walking Route Planning: Walking route planning

如何使用

How to Use

推荐决策路径
  1. 用户需求是多步串联场景(如"输入地名规划路线"、"获取附近 POI")→ 直接找
    recipes/
    目录下对应 recipe
  2. 用户需求是单个 API 的参数细节(如"这个接口的 tactics 参数有哪些值")→ 查阅
    references/
    目录
每个 references 参考文件包含:
  • 功能简要说明
  • API 参数说明和注意事项
每个 recipes 场景包含:
  • 触发意图(什么场景适用)
  • 完整调用链与分步说明
  • 常见错误和变体
Recommended Decision Path:
  1. If the user's requirement is a multi-step serial scenario (e.g., "Input place name to plan route", "Obtain nearby POIs") → Directly find the corresponding recipe in the
    recipes/
    directory
  2. If the user's requirement is parameter details of a single API (e.g., "What values are available for the tactics parameter of this interface") → Refer to the
    references/
    directory
Each references document includes:
  • Brief function description
  • API parameter descriptions and notes
Each recipes scenario includes:
  • Trigger intent (what scenario it applies to)
  • Complete call chain and step-by-step instructions
  • Common errors and variants