0
1

More than 1 year has passed since last update.

【さっぽろえきバスナビ】バス接近情報(バスロケーション)APIをjsonで取得する

Posted at

さっぽろえきバスナビとは?

札幌市が運営している札幌市内の公共交通機関の経路案内や時刻表を載せているウェブサイトです。
AndroidやiPhoneアプリも公開されています。

バスロケーションシステムとは?

バスの走行位置・遅れ時間が分かる機能で、2021年から導入されました。
札幌市内を走るほとんどのバス路線に対応しています。

路線ごとの接近情報を取得する

Get_busstop_lastdataGet_busstop_list のAPIを使って取得することができます。ただし、それぞれのバス停の発車時刻は取得できません。

※APIはいろいろありますが、バスロケーションシステムに関係するAPIのみ掲載しています。

電車(JR北海道)とは違いAPIになっているため、取得したいデータを指定して POST で送ってあげる必要があります。

course_idstation_id が必要です。

course_id 路線番号
station_id 停留所番号

get_busstop_list_set API(検索API)を使って取得することができます。

バス停一覧(Get_busstop_lastdata)

POST先URL
https://ekibus-api.city.sapporo.jp/Get_busstop_lastdata

ペイロードに、course_idstation_id を指定します。

post_data
{
  'kind' : '0',
  'course_id' : course_id,
  'station_id' : station_id,
  'lang' : ''
}

以下のような形で返ってきます。

Get_busstop_lastdata(抜粋)
{
    "result": "0",
    "course_id": "340113",
    "station_last_id": "340002",
    "station_data_list": [
        {
            "station_id": "340238",
            "name": "新札幌駅(新札幌ターミナル)"
        },
        {
            "station_id": "340237",
            "name": "東商業高校前"
        },
        {
            "station_id": "340236",
            "name": "厚別西通"
        },

station_data_list の中身がバス停一覧になっています。

station_last_id はこの後の処理で使います。

バス現在位置(Get_busstop_list)

POST先URL
https://ekibus-api.city.sapporo.jp/Get_busstop_list

ペイロードに、course_id_liststation_id_list を指定します。

post_data
{
  'kind' : '0',
  'course_id_list' : course_id,
  'station_id_list' : station_id_list,
  'lang' : ''
}

course_id_listcourse_id と同じ値です。

station_id_listGet_busstop_lastdata APIで取得した値を使います。

以下のような形で返ってきます。

Get_busstop_list(抜粋)
{
    "result": "0",
    "data": [
        {
            "line_id": 340153,
            "line_name": "新札幌線[1]",
            "course_id": "340113",
            "course_id_name": "新札幌駅→JR札幌駅",
            "station_id": "340002",
            "station_id_name": "時計台前(市役所)",
            "pos": 25,
            "stop_no": "1",
            "terminal_flg": 0,
            "time_list": [
               {
                    "time": "10:40",
                    "start_time": "10:00",
                    "bus_status": 0,
                    "last_stop": 340237,
                    "last_stop_order": 1,
                    "delay_time": 1,
                    "course_id": "340113",
                    "note": "",
                    "barrier_free": 1
                },
time_listの見方
JSONの仕様
名前 説明
bus_status 運行状態(0:運行中)
last_stop_order 終着までのバス停数
start_time 始発の時間
time 終着の到着時間
delay_time 遅延時間(分単位)
note 備考
last_stop 現在位置
barrier_free ノンステップバス
course_id 路線番号

つまり、time_list の中で、bus_status1 になっている last_stop を抽出すれば、バスの現在位置を知ることができます。
しかし、抽出できたバスの現在位置 lase_stop はバス停番号 station_id
の状態のため、バス停一覧(Get_busstop_lastdata)API で取得した、バス停リスト station_data_list を使って、バス停名にすると見やすくなります。

編集後記

さっぽろえきバスナビのAPIについてインターネット上を探しても、解説記事等全くヒットしなかったので、私用のメモとしてまとめました。地方だからでしょうか……

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1