Appearance
交通事件 API
交通事件API提供了获取城市实时交通事件信息的功能,包括事故、封路、施工等影响交通的信息。
获取交通事件 API
接口描述
获取指定城市的交通事件信息,包括事故位置、事件描述、开始和结束时间等详细信息。
TIP
交通事件信息实时更新,建议根据业务需求设置合适的请求频率
请求方式
| URL | 请求方式 |
|---|---|
| https://lbs.xiaojukeji.com/api/v2/traffic/incident | GET |
请求
查询参数(GET)
| 参数名 | 必选 | 类型 | 描述 | 示例值 |
|---|---|---|---|---|
| key | 是 | string | 鉴权用的 API Key | YOUR_API_KEY |
| citycode | 是 | string | 城市代码,见城市代码表 | 1 |
| eventtype | 是 | string | 事件类型 | 100 |
| startid | 是 | string | 开始id | 0 |
| format | 是 | string | 返回格式,protobuf/json | json |
事件类型说明
事件类型(eventtype)参数用于筛选不同类型的交通事件:
| 事件类型 | 描述 |
|---|---|
| 100 | 事故 |
| 200 | 施工 |
| 300 | 管制 |
| 400 | 封路 |
| 500 | 积水 |
全量/增量获取
- 首次请求时,startid 参数传入 0,返回全量数据
- 后续请求时,startid 参数传入上一次响应中 results.lastTraceId 的值,返回增量数据
请求示例
shell
curl -X GET "https://lbs.xiaojukeji.com/api/v2/traffic/incident?key=YOUR_API_KEY&citycode=1&eventtype=100&startid=0&format=json"响应
成功响应为 TrafficIncidentResponse 模型的JSON格式。
响应示例
json
{
"status": 10000,
"msg": "OK",
"trace_id": "0ac5186e67e513a96bd404838be2d3b0",
"results": {
"eventsData": [
{
"eventID": 470037591,
"eventType": 100,
"brief": "裕安路发生事故",
"eventDesc": "裕安路发生事故",
"roadName": "裕安路",
"expressway": false,
"startTime": 1747033837,
"endTime": 1747034737,
"updateTime": 1747034008,
"x": 116.54529,
"y": 40.08189,
"lines": [
{
"longitude": 116.54529,
"latitude": 40.08189
}
]
}
],
"lastTraceId": 470037591
}
}protobuf 格式说明
proto 格式返回的是二进制数据,需要使用 proto 解析器进行解析。
proto
message GeoPoint {
required float x = 1; // 小于等于0无效
required float y = 2; // 小于等于0无效
}
message Shape {
repeated GeoPoint point_list = 1;
}
message EventInfo {
required uint64 eventid = 1; // 0无效
required uint32 country_code = 3; // 0无效
required uint32 city_code = 4; // 0无效
required uint32 operation = 5; // 操作码,1增加,2修改,3删除,0无效
optional uint32 type = 8; // 事件类型,参见定义,0无效
optional uint32 sub_type = 9; // 事件子类型,参见定义,0无效
optional uint32 shape_type = 10; // 形状类型,1 点事件,2线事件,3面事件,0无效
optional GeoPoint show_point = 13; // 显示位置
optional uint32 direction = 14; // 事件方向,正北顺时针度,大于360无效
optional uint32 confidence = 15; // 可信度0~100,大于100无效
repeated Shape shape = 20; // 事件形状
optional string road_name = 24; // 道路名
optional int32 influence = 27; // 重要
optional uint64 linkid = 28; // 0无效
optional uint32 road_grade = 30; // 道路等级 0高速,1快速路,2国道,3省道,4县道,6乡到,8其它道路,9九级道路,10轮渡,11人行道,大于等于0XFFFFFFFF无效
optional uint32 road_type = 31; // 道路属性 0环岛,1无属性,2上下线分离,3JCT,4交叉点内Link,5IC,6停车区,7服务区,8桥,9步行街,10辅路,详细参见四维数据定义,大于等于0XFFFFFFFF无效
required uint64 trace_id = 34; // trace id 0无效
}
message EventList {
repeated EventInfo event = 1;
required int32 code = 2;
required string message = 3;
optional bool is_all_snap = 4;
optional uint64 size = 5;
optional uint64 last_trace_id = 6;
}