駅情報API(/station)のdirectionパラメータを解説する #駅すぱあとWebサービス
こんにちは。 駅すぱあとWebサービスで使われてる機能、トップ3に入るんじゃないかと噂される(※体感値)駅情報API。今回はその駅情報APIのパラメータの一つであるdirectionパラメータを紹介します。
directionパラメータはrailNameパラメータ、またはoperationLineCodeパラメータと一緒に使うものです。 路線にひもづく駅を取得する際に、路線の方向をdirectionパラメータで指定します。
ちなみに以下がドキュメントに記載されたdirectionパラメータの説明。
路線の停車駅取得方向。railName, operationLineCode 指定時のみ有効。
指定できる値:
- up: 通常
- down: 反転
- none: 指定なし
Default: up
駅情報 - 駅すぱあとWebサービス Documents 駅データ・路線検索のWebAPIより
ユーザー様 「・・・『通常』、『反転』とかどういう意味じゃコラ(;゚ロ゚)」
丸山 「 わかりづらくて、すみません!!m(_ _)m」
はい。ということで、ドキュメントではさらっと説明されているdirectionパラメータについて詳しく解説していきます。
up
駅を通常方向順に取得します。平均路線JR中央線快速
で例えると、高尾→東京の方向に値します。
curl "https://api.ekispert.jp/v1/json/station?key=xxx&railName=JR中央線快速&direction=up"
{ "ResultSet": { "apiVersion": "1.27.0.0", "engineVersion": "201804_04a", "RoundTripType": "same", "Point": [ { "onRouteEdge": "False", "getOff": "False", "onRoute": "True", "getOn": "True", "Station": { "code": "22787", "Name": "高尾(東京都)", "Type": "train", "Yomi": "たかお" }, "Prefecture": { "code": "13", "Name": "東京都" }, "GeoPoint": { "longi": "139.17.5.79", "lati": "35.38.20.29", "longi_d": "139.284944", "lati_d": "35.638971", "gcs": "tokyo" } }, : (省略) : { "onRouteEdge": "False", "getOff": "True", "onRoute": "True", "getOn": "False", "Station": { "code": "22828", "Name": "東京", "Type": "train", "Yomi": "とうきょう" }, "Prefecture": { "code": "13", "Name": "東京都" }, "GeoPoint": { "longi": "139.46.13.59", "lati": "35.40.41.9", "longi_d": "139.770444", "lati_d": "35.678083", "gcs": "tokyo" } } ] } }
down
駅を反転方向順に取得します。平均路線JR中央線快速
で例えると、東京→高尾の方向に値します。
curl "https://api.ekispert.jp/v1/json/station?key=xxx&railName=JR中央線快速&direction=down"
{ "ResultSet": { "apiVersion": "1.27.0.0", "engineVersion": "201804_04a", "RoundTripType": "same", "Point": [ { "onRouteEdge": "False", "getOff": "False", "onRoute": "True", "getOn": "True", "Station": { "code": "22828", "Name": "東京", "Type": "train", "Yomi": "とうきょう" }, "Prefecture": { "code": "13", "Name": "東京都" }, "GeoPoint": { "longi": "139.46.13.59", "lati": "35.40.41.9", "longi_d": "139.770444", "lati_d": "35.678083", "gcs": "tokyo" } }, : (省略) : { "onRouteEdge": "False", "getOff": "True", "onRoute": "True", "getOn": "False", "Station": { "code": "22787", "Name": "高尾(東京都)", "Type": "train", "Yomi": "たかお" }, "Prefecture": { "code": "13", "Name": "東京都" }, "GeoPoint": { "longi": "139.17.5.79", "lati": "35.38.20.29", "longi_d": "139.284944", "lati_d": "35.638971", "gcs": "tokyo" } } ] } }
none
up, downの指定をせず、どちらか片方の方向順に取得します。
up, downどちらか一方しか存在しない路線(平均路線JR山手線内回り
やJR大阪環状線内回り
など)が存在するため、noneを指定することでリクエストの手間を省くことができます。
curl "https://api.ekispert.jp/v1/json/station?key=xxx&railName=JR山手線内回り&direction=none"
{ "ResultSet": { "apiVersion": "1.27.0.0", "engineVersion": "201804_04a", "RoundTripType": "other", "Point": [ { "onRouteEdge": "False", "getOff": "False", "onRoute": "True", "getOn": "True", "Station": { "code": "22828", "Name": "東京", "Type": "train", "Yomi": "とうきょう" }, "Prefecture": { "code": "13", "Name": "東京都" }, "GeoPoint": { "longi": "139.46.13.59", "lati": "35.40.41.9", "longi_d": "139.770444", "lati_d": "35.678083", "gcs": "tokyo" } }, : (省略) :
駅がない?
directionパラメータはデフォルト値(up)が設定されており、指定は必須ではありません。
directionパラメータ未指定でrailNameパラメータにJR山手線内回り
を指定すると、「?!駅がない!!」という事態に見舞われます。
curl "https://api.ekispert.jp/v1/json/station?key=xxx&railName=JR山手線内回り"
{ "ResultSet": { "apiVersion": "1.27.0.0", "engineVersion": "201804_04a", "RoundTripType": "other" } }
駅すぱあとでは、JR山手線内回り
はdownでのみ存在します。directionパラメータにdown、またはnoneを指定してあげればちゃんと駅が出てきます。