駅・路線検索API仕様
概要
- 駅・路線情報をAPIで提供しています。
- 個人、商用共に無料で利用できます。リクエスト回数や頻度の制限は設けておりません。常識の範囲にてご利用ください。
- データは無料版を使っているため、新幹線の駅情報や路線の詳細情報が欠落しています。収益化の見通しがたったら有料版のデータを購入したいと思います。(4,400円/6ヶ月) 寄付募集中
REST API仕様書
API仕様書はOpen API 3フォーマットで記載しています。仕様書は以下のページに記載してあります。
APIサーバ可動状況
BetterUptimeによる外部監視を行っています。
API呼び出し例
山手線の駅名と座標の一覧をCSVで取得 API仕様
curl -s https://train.teraren.com/lines/11302/stations.json | jq -r '.[] | [.station_name, .lon, .lat] | @csv'
"大崎","139.728439","35.619772"
"五反田","139.723822","35.625974"
"目黒","139.715775","35.633923"
"恵比寿","139.71007","35.646685"
"渋谷","139.701238","35.658871"
"原宿","139.702592","35.670646"
"代々木","139.702042","35.683061"
"新宿","139.700464","35.689729"
"新大久保","139.700261","35.700875"
"高田馬場","139.703715","35.712677"
"目白","139.706228","35.720476"
"池袋","139.711086","35.730256"
"大塚","139.728584","35.731412"
"巣鴨","139.739303","35.733445"
"駒込","139.748053","35.736825"
"田端","139.761229","35.737781"
"西日暮里","139.766857","35.731954"
"日暮里","139.771287","35.727908"
"鶯谷","139.778015","35.721484"
"上野","139.777043","35.71379"
"御徒町","139.774727","35.707282"
"秋葉原","139.773288","35.698619"
"神田","139.770641","35.691173"
"東京","139.766103","35.681391"
"有楽町","139.763806","35.675441"
"新橋","139.758587","35.666195"
"浜松町","139.757135","35.655391"
"田町","139.747575","35.645736"
"高輪ゲートウェイ","139.7407","35.6355"
"品川","139.738999","35.62876"
路線名の一覧を取得 API仕様
curl -s https://train.teraren.com/lines.json | jq '.[].line_name'
"中央新幹線"
"東海道新幹線"
"山陽新幹線"
"東北新幹線"
"上越新幹線"
"上越新幹線(ガーラ湯沢支線)"
"山形新幹線"
"秋田新幹線"
"北陸新幹線"
"九州新幹線"
"北海道新幹線"
"JR函館本線(函館~長万部)"
"JR函館本線(長万部~小樽)"
"JR函館本線(小樽~旭川)"
"JR室蘭本線(長万部・室蘭~苫小牧)"
"JR室蘭本線(苫小牧~岩見沢)"
"JR根室本線(滝川~新得)"
"JR根室本線(新得~釧路)"
"花咲線"
"JR千歳線"
"JR石勝線"
"JR日高本線"
"JR札沼線"
"JR留萌本線"
"JR富良野線"
特定の緯度経度から近い順で駅の一覧を取得。(東京タワーから最寄りの駅を取得) API仕様
curl 'https://train.teraren.com/stations/near_by_stations.json?lon=139.7454316&lat=35.658584' | jq 'limit(5; .[])'
{
"station_cd": 9930122,
"station_name": "赤羽橋",
"station_g_cd": 9930122,
"distance": 0.4293522820451477
}
{
"station_cd": 2800317,
"station_name": "神谷町",
"station_g_cd": 2800317,
"distance": 0.48968747581839894
}
{
"station_cd": 9930306,
"station_name": "御成門",
"station_g_cd": 9930306,
"distance": 0.6242133516473801
}
{
"station_cd": 9930305,
"station_name": "芝公園",
"station_g_cd": 9930305,
"distance": 0.639515764707121
}
{
"station_cd": 9930209,
"station_name": "大門",
"station_g_cd": 9930121,
"distance": 0.8574239732003268
}
現在地から近い駅を表示 API仕様
ここに出力されます。
stimulusによるサンプルコード
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "lon", "lat", "output" ]
getLocation() {
if (!('geolocation' in navigator)) {
alert('Allow browser to acquire location.');
}
navigator.geolocation.getCurrentPosition((position) => {
this.latTarget.value = position.coords.latitude;
this.lonTarget.value = position.coords.longitude;
}, (error) => {
alert(error.message);
});
}
search() {
const url = `/stations/near_by_stations.json?lon=${this.lonTarget.value}&lat=${this.latTarget.value}&limit=5`;
fetch(url)
.then(response => response.json())
.then((json) => JSON.stringify(json, null, 2))
.then((json_string) => { this.outputTarget.textContent = json_string; });
}
}