实时公交
查询全国城市公交站点的实时到站信息,支持切换方向
接口信息
| 项目 | 内容 |
|---|---|
| 接口地址 | https://api.code410.com/api/traffic/bus |
| 返回格式 | application/json |
| 请求方式 | HTTP GET |
| 更新日期 | 2026-06-15 |
| 调用权限 | 免费开放 |
| 每日限制 | 全站API 10万次/日 |
请求示例
https://api.code410.com/api/traffic/bus?city=城市名&site=站点名请求参数说明
| 名称 | 必填 | 类型 | 示例值 | 说明 |
|---|---|---|---|---|
| city | 是 | string | 深圳 | 城市名 |
| site | 是 | string | 京基 | 站点名 |
| backward | 否 | int | 1 | 传 1 切换到反方向,不传为正方向 |
返回参数说明
| 名称 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码 |
| msg | string | 状态信息 |
| data | object | 结果数据集,键为”城市-站点”,值为该站各线路实时到站数组;查不到时为提示文本 |
| line | string | 公交线路名 |
| price | string | 票价 |
| destination | string | 开往方向(终点站) |
| licence_plate | string | 车牌号 |
| expected_arrival | string | 预计到站时间 |
| estimated_time | string | 预计还需时间 |
| remaining_stations | string | 剩余站数 |
| exec_time | float | 执行耗时 |
| ip | string | 客户端IP |
错误码参照
| 错误码 | 类型 | 说明 |
|---|---|---|
| 403 | int | 没有权限 |
| 400 | int | 参数传递不正确 |
| 500 | int | 服务器内部错误 |
返回示例
{
"code": 200,
"msg": "请求成功",
"data": {
"深圳-京基": [
{
"line": "781路🚌",
"price": "3元",
"destination": "会展湾东城公交首末站",
"licence_plate": "粤B77880D",
"expected_arrival": "2026-06-15 22:44",
"estimated_time": "41分⏱",
"remaining_stations": "22站"
}
]
},
"exec_time": 0.412,
"ip": "197.149.235.178"
}示例代码
// jQuery-Ajax
$.ajax({
url: 'https://api.code410.com/api/traffic/bus',
data: {
city: "深圳",
site: "京基",
backward: "",
},
type: 'GET',
dataType: 'json',
success: function (data) {
console.log(data); // 请求成功,输出结果
},
error: function () {
console.log('请求失败');
}
});import requests
url = "https://api.code410.com/api/traffic/bus"
params = {
"city": "深圳",
"site": "京基",
"backward": "",
}
res = requests.get(url, params=params)
print(res.json())const https = require('https');
const url = 'https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward=';
https.get(url, res => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => console.log(JSON.parse(data)));
}).on('error', err => console.error(err));package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
resp, err := http.Get("https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward=")
if err != nil {
fmt.Println("http get error", err)
return
}
defer resp.Body.Close()
result, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(result))
}import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Test {
public static void main(String[] args) {
try {
URL url = new URL("https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward=");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) sb.append(line);
reader.close();
System.out.println(sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main() {
HttpClient client = new HttpClient();
string url = "https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward=";
HttpResponseMessage response = await client.GetAsync(url);
string body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
}<?php
$url = "https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward=";
$response = file_get_contents($url);
$data = json_decode($response, true);
print_r($data);curl "https://api.code410.com/api/traffic/bus?city=%E6%B7%B1%E5%9C%B3&site=%E4%BA%AC%E5%9F%BA&backward="在线调试
填写参数后点击「发起请求」查看实时返回结果。
