ลูกค้าของบริการขนส่งสาธารณะเบอร์ลินและบรันเดนบูร์ก (VBB) โดยทำหน้าที่เป็นอินเทอร์เฟซที่สอดคล้องกันและตรงไปตรงมาบน API แบบละเอียด
จริงๆ แล้วโปรเจ็กต์นี้เป็นเพียงเสื้อคลุมบางๆ รอบ ๆ hafas-client@6
เอกสารของมันจัดทำเอกสาร API โดยทั่วไป
หมายเหตุ : คุณอาจไม่ต้องการสืบค้น VBB API ด้วยตัวเอง vbb-client
เป็นไคลเอนต์ที่เข้ากันได้กับ API สำหรับ vbb-rest
ซึ่งเป็น wrapper API ของฉัน มันยังใช้งานได้ในเบราว์เซอร์
npm install vbb-hafas
ตรวจสอบเอกสารสำหรับ hafas-client
รวมถึงการปรับแต่งเฉพาะ VBB
const createHafas = require ( 'vbb-hafas' )
const hafas = createHafas ( 'my-awesome-program' )
ตัวอย่างเช่น เราจะค้นหาการเดินทางจาก Berlin Hauptbahnhof ไปยัง Berlin Charlottenburg หากต้องการรับรหัสสถานี ให้ใช้ vbb-stations
hafas . journeys ( '900000003201' , '900000024101' , { results : 1 } )
. then ( ( journeys ) => console . log ( journeys [ 0 ] ) )
. catch ( console . error )
ผลลัพธ์จะเป็นอาร์เรย์ของออบเจ็กต์ journey
ใน รูปแบบ 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
จะพยายามเพิ่มข้อมูลการถ่ายโอนจาก vbb-change-positions
หากคุณส่งผ่าน transferInfo: true
เป็นตัวเลือก
หากระบุการถ่ายโอนที่ทราบ เลกก่อนหน้าจะมี bestArrivalPosition
และเลกถัดไปจะมี departurePosition
ซึ่งบ่งบอกถึงการถ่ายโอนที่เหมาะสมที่สุดระหว่างทั้งสองแพลตฟอร์ม ตรวจสอบมาร์กอัปใน vbb-change-positions
เพื่อดูรายละเอียดเพิ่มเติม
ตรวจสอบโครงการที่เกี่ยวข้องของ hafas-client
หากคุณ มีคำถาม พบข้อบกพร่อง หรือต้องการ เสนอคุณลักษณะ โปรดดูที่หน้าปัญหา