Klien untuk layanan transportasi umum Berlin & Brandenburg (VBB). Ini bertindak sebagai antarmuka yang konsisten dan lugas di atas API verbose.
Proyek ini sebenarnya merupakan pembungkus tipis hafas-client@6
. Dokumennya mendokumentasikan API secara umum.
Catatan : Anda mungkin tidak ingin menanyakan sendiri VBB API. vbb-client
adalah klien yang kompatibel dengan API untuk vbb-rest
, API pembungkus saya. Ini juga berfungsi di browser.
npm install vbb-hafas
Periksa dokumen untuk hafas-client
serta penyesuaian khusus VBB-nya.
const createHafas = require ( 'vbb-hafas' )
const hafas = createHafas ( 'my-awesome-program' )
Sebagai contoh, kita akan mencari perjalanan dari Berlin Hauptbahnhof ke Berlin Charlottenburg . Untuk mendapatkan ID stasiun, gunakan vbb-stations
.
hafas . journeys ( '900000003201' , '900000024101' , { results : 1 } )
. then ( ( journeys ) => console . log ( journeys [ 0 ] ) )
. catch ( console . error )
Outputnya akan berupa array objek journey
dalam format Friendly Public Transport Format 1.2.1
:
[ {
legs : [ {
tripId : '1|50420|0|86|25122017' ,
direction : 'Brandenburg, Hbf' ,
line : {
type : 'line' ,
id : '10' ,
name : 'RE1' ,
public : true ,
mode : 'train' ,
product : 'regional' ,
symbol : 'RE' ,
nr : 1 ,
metro : false ,
express : true ,
night : false ,
class : 64 ,
productCode : 6 ,
operator : {
type : 'operator' ,
id : 'db-regio-ag' ,
name : 'DB Regio AG'
}
} ,
origin : {
type : 'station' ,
id : '900000003201' ,
name : 'S+U Berlin Hauptbahnhof' ,
location : {
type : 'location' ,
latitude : 52.52585 ,
longitude : 13.368928
} ,
products : {
suburban : true ,
subway : true ,
tram : true ,
bus : true ,
ferry : false ,
express : true ,
regional : true
}
} ,
departure : '2017-12-26T00:41:00.000+01:00' ,
plannedDeparture : '2017-12-26T00:41:00.000+01:00' ,
departureDelay : 0 ,
departurePlatform : '14' ,
plannedDeparturePlatform : '13' ,
destination : {
type : 'station' ,
id : '900000024101' ,
name : 'S Charlottenburg' ,
location : {
type : 'location' ,
latitude : 52.504806 ,
longitude : 13.303846
} ,
products : {
suburban : true ,
subway : false ,
tram : false ,
bus : true ,
ferry : false ,
express : false ,
regional : true
}
} ,
arrival : '2017-12-26T00:50:00.000+01:00' ,
plannedArrival : '2017-12-26T00:50:00.000+01:00' ,
arrivalDelay : null ,
arrivalPlatform : '4' ,
plannedArrivalPlatform : '4'
} ] ,
// all these are from the first leg
origin : {
type : 'station' ,
id : '900000003201' ,
name : 'S+U Berlin Hauptbahnhof'
// …
} ,
departure : '2017-12-26T00:41:00.000+01:00' ,
plannedDeparture : '2017-12-26T00:41:00.000+01:00' ,
departureDelay : 0 ,
departurePlatform : '14' ,
plannedDeparturePlatform : '13' ,
// all these are from the last leg
destination : {
type : 'station' ,
id : '900000024101' ,
name : 'S Charlottenburg'
// …
} ,
arrival : '2017-12-26T00:50:00.000+01:00' ,
plannedArrival : '2017-12-26T00:50:00.000+01:00' ,
arrivalDelay : null ,
arrivalPlatform : '4' ,
plannedArrivalPlatform : '4'
// …
} ]
vbb-hafas
akan mencoba menambahkan informasi transfer dari vbb-change-positions
jika Anda meneruskan transferInfo: true
sebagai opsi.
Jika ini mengidentifikasi transfer yang diketahui, babak sebelumnya akan memiliki bestArrivalPosition
dan babak berikutnya akan memiliki departurePosition
, yang menunjukkan transfer optimal antara kedua platform. Lihat markup di vbb-change-positions
untuk lebih jelasnya.
Periksa proyek terkait hafas-client
.
Jika Anda mempunyai pertanyaan , menemukan bug , atau ingin mengusulkan fitur , lihat halaman masalah.