vbb hafas
1.0.0
柏林和勃兰登堡公共交通服务 (VBB) 的客户。它充当详细 API 之上的一致且简单的接口。
该项目实际上是hafas-client@6
的薄包装。它的文档总体上记录了 API。
注意:您可能不想自己查询 VBB API。 vbb-client
是vbb-rest
(我的包装 API)的 API 兼容客户端。它也适用于浏览器。
npm install vbb-hafas
检查hafas-client
的文档及其特定于 VBB 的自定义。
const createHafas = require ( 'vbb-hafas' )
const hafas = createHafas ( 'my-awesome-program' )
例如,我们将搜索从Berlin Hauptbahnhof到Berlin Charlottenburg的旅程。要获取站 ID,请使用vbb-stations
。
hafas . journeys ( '900000003201' , '900000024101' , { results : 1 } )
. then ( ( journeys ) => console . log ( journeys [ 0 ] ) )
. catch ( console . error )
输出将是友好公共交通格式1.2.1
格式的journey
对象数组:
[ {
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'
// …
} ]
如果您传递transferInfo: true
作为选项, vbb-hafas
将尝试从vbb-change-positions
添加转移信息。
如果它识别出已知的换乘,则前一航段将具有bestArrivalPosition
,下一航段将具有departurePosition
,指示两个平台之间的最佳换乘。查看vbb-change-positions
中的标记以了解更多详细信息。
检查hafas-client
的相关项目。
如果您有疑问、发现错误或想要提出功能,请查看问题页面。