简单做了一个上海公交信息 API 查询

2019-01-31 11:43:48 +08:00
 stephenroger

github: https://github.com/gyfstephen/shanghai-bus

上海发布里查询准确度不错,但是查询体验不是很好,会经常卡住,所以就简单抓了下上海发布查公交的接口自己集成了实现一个 API,现在应该只支持查询车辆名为纯数字的线路

数据来源:上海发布

API 接口:

示例:

{
    "data": {
        "1": "吉浦路仁德路", 
        "2": "武川路武东路", 
        "3": "武川路政立路", 
        "4": "政立路国权北路", 
        "5": "政立路逸仙路", 
        "6": "逸仙路场中路", 
        "7": "江湾(逸仙路)", 
        "8": "逸仙路纪念路", 
        "9": "大柏树(曲阳路)", 
        "10": "曲阳路中山北二路", 
        "11": "大连西路曲阳路", 
        "12": "欧阳路大连西路", 
        "13": "欧阳路祥德路", 
        "14": "欧阳路四达路", 
        "15": "欧阳路吉祥路", 
        "16": "四平路溧阳路", 
        "17": "吴淞路海宁路", 
        "18": "吴淞路天潼路"
    }, 
    "error": 0, 
    "msg": ""
}
{
    "data": [
        {
            "distance": 0, 
            "error": 0, 
            "plate": "沪 A-00737D", 
            "station_name": "吉浦路仁德路", 
            "stop_dis": 1, 
            "stop_id": 1, 
            "time": 929
        }, 
        {
            "distance": 1296, 
            "error": 0, 
            "plate": "沪 A-00737D", 
            "station_name": "武川路武东路", 
            "stop_dis": 1, 
            "stop_id": 2, 
            "time": 1048
        }, 
        {
            "distance": 1548, 
            "error": 0, 
            "plate": "沪 A-00737D", 
            "station_name": "武川路政立路", 
            "stop_dis": 2, 
            "stop_id": 3, 
            "time": 1110
        }, 
        {
            "distance": 2203, 
            "error": 0, 
            "plate": "沪 A-00737D", 
            "station_name": "政立路国权北路", 
            "stop_dis": 3, 
            "stop_id": 4, 
            "time": 1289
        }, 
        {
            "distance": 576, 
            "error": 0, 
            "plate": "沪 A-01825D", 
            "station_name": "政立路逸仙路", 
            "stop_dis": 1, 
            "stop_id": 5, 
            "time": 88
        }, 
        {
            "distance": 1175, 
            "error": 0, 
            "plate": "沪 A-01825D", 
            "station_name": "逸仙路场中路", 
            "stop_dis": 2, 
            "stop_id": 6, 
            "time": 208
        }, 
        {
            "distance": 1590, 
            "error": 0, 
            "plate": "沪 A-01825D", 
            "station_name": "江湾(逸仙路)", 
            "stop_dis": 3, 
            "stop_id": 7, 
            "time": 269
        }, 
        {
            "distance": 1882, 
            "error": 0, 
            "plate": "沪 A-01825D", 
            "station_name": "逸仙路纪念路", 
            "stop_dis": 4, 
            "stop_id": 8, 
            "time": 388
        }, 
        {
            "distance": 3142, 
            "error": 0, 
            "plate": "沪 A-01825D", 
            "station_name": "大柏树(曲阳路)", 
            "stop_dis": 5, 
            "stop_id": 9, 
            "time": 628
        }, 
        {
            "distance": 293, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "曲阳路中山北二路", 
            "stop_dis": 1, 
            "stop_id": 10, 
            "time": 31
        }, 
        {
            "distance": 1642, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "大连西路曲阳路", 
            "stop_dis": 2, 
            "stop_id": 11, 
            "time": 331
        }, 
        {
            "distance": 2170, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "欧阳路大连西路", 
            "stop_dis": 3, 
            "stop_id": 12, 
            "time": 449
        }, 
        {
            "distance": 2579, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "欧阳路祥德路", 
            "stop_dis": 4, 
            "stop_id": 13, 
            "time": 569
        }, 
        {
            "distance": 2867, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "欧阳路四达路", 
            "stop_dis": 5, 
            "stop_id": 14, 
            "time": 630
        }, 
        {
            "distance": 3196, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "欧阳路吉祥路", 
            "stop_dis": 6, 
            "stop_id": 15, 
            "time": 689
        }, 
        {
            "distance": 4019, 
            "error": 0, 
            "plate": "沪 A-07566D", 
            "station_name": "四平路溧阳路", 
            "stop_dis": 7, 
            "stop_id": 16, 
            "time": 870
        }, 
        {
            "distance": 728, 
            "error": 0, 
            "plate": "沪 A-05870D", 
            "station_name": "吴淞路海宁路", 
            "stop_dis": 1, 
            "stop_id": 17, 
            "time": 90
        }, 
        {
            "distance": 1329, 
            "error": 0, 
            "plate": "沪 A-05870D", 
            "station_name": "吴淞路天潼路", 
            "stop_dis": 2, 
            "stop_id": 18, 
            "time": 330
        }
    ], 
    "error": 0, 
    "msg": ""
}

TODO:

4044 次点击
所在节点    分享创造
4 条回复
zli
2019-01-31 13:00:01 +08:00
为什么不用巴士通的 API,

那个接口不是更直接更全面?
exceloo
2019-01-31 13:16:13 +08:00
这个擅自搭建 api 获取公共信息有没有什么风险?就像自己画地图被抓起来那样...
Senventise
2019-01-31 13:47:38 +08:00
之前也写过一个,话说 sid 我记得好像就是线路名的 md5 啊,为什么查不了非数字线路?
btw,上海公交官方 app 也不错,用的是同一套 api
kimown
2019-02-02 12:57:36 +08:00
@exceloo

有家公司,产品叫 车来了,而且融资了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/532106

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX