A simple API adapter for fetching live data (timetables, stations, lines, messages, incidents, etc.) from MVG (Münchner Verkehrsgesellschaft)
npm install --save-dev mvg
const mvg = require('mvg');
mvg.getStations().then((stations) => {
const demo = stations.find((station) => station.name === 'Universität');
mvg.getDepartures(demo.id).then((departures) => {
console.log(departures);
});
});
Fetches all known messages like incidents or schedule changes
mvg.getMessages().then((messages) => {
console.log(messages);
});
[
{
"title": "Ab ca. 22.00 Uhr abschnittsweise Bus statt U-Bahn (SEV) wegen Schienenschleifarbeiten",
"description": "Wegen Schienenschleifarbeiten wird die U2 von Montag, 9. April mit Donnerstag, 12. April 2018, jeweils ab ca. 22.00 Uhr bis Betriebsschluss, zwischen Innsbrucker Ring und Messestadt Ost durch Busse ersetzt. Letzte durchfahrende Züge: Ab Messestadt Ost 22.15 Uhr, ab Feldmoching 21.34 Uhr (Hauptbahnhof 21.52 Uhr).",
"publication": 1522131665000,
"validFrom": 1523239200000,
"validTo": 1523570340000,
"id": "227050003",
"links": [
{
"text": "Für weitere Informationen bitte hier klicken / For further information please klick here",
"url": "https://www.mvg.de/betriebsaenderungen/2018-03-25-schienenschleifzug"
}
],
"type": "SCHEDULE_CHANGES",
"lines": [
{
"sev": false,
"product": "UBAHN",
"lineNumber": "U2",
"divaId": "UBAHNU2"
}
],
"eventTypes": []
}
]
Fetches all known incidents
mvg.getIncidents().then((incidents) => {
console.log(incidents);
});
[
{
"title": "Verkehrsbedingte Fahrplanabweichungen",
"description": "Liebe Fahrgäste,<br /><br />bei der Buslinie 100 kommt es derzeit wegen der Sperrung des Altstadtringtunnels zu Beeinträchtigungen. Es ist mit Verspätungen sowie vereinzelten Fahrzeugausfällen und vorzeitigen Wendungen zu rechnen. Die Behinderungen dauern noch vsl. bis 3. April an. Bitte planen Sie daher längere Reisezeiten ein.<br /><br />Wir bitten wir um Ihr Verständnis.<br /> <br />Ihre MVG",
"publication": 1522057217000,
"validFrom": 1522057200000,
"validTo": 1522792500000,
"id": "2055043199",
"type": "INCIDENT",
"lines": [
{
"sev": false,
"product": "BUS",
"lineNumber": "100",
"divaId": "BUS100"
}
],
"eventTypes": []
}
]
Fetches all available lines
mvg.getLines().then((lines) => {
console.log(lines);
});
[
{
"sev": false,
"partialNet": "mvv",
"product": "SBAHN",
"lineNumber": "S1",
"divaId": "01001"
}
]
Fetches all available stations
mvg.getStations().then((stations) => {
console.log(stations);
});
[
{
"type": "station",
"latitude": 48.1391669640734,
"longitude": 11.5652403434013,
"id": 1,
"place": "München",
"name": "Karlsplatz (Stachus)",
"hasLiveData": true,
"hasZoomData": true,
"products": [
"SBAHN",
"UBAHN",
"TRAM",
"BUS"
],
"aliases": "Stachus Bf. Bahnhof Muenchen Munchen",
"link": "KA",
"lines": {
"tram": [],
"nachttram": [],
"sbahn": [],
"ubahn": [],
"bus": [],
"nachtbus": [],
"otherlines": []
}
}
]
Fetches serving lines and departures for a specific station
- (
String
|Number
)stationId
(Required) The station ID - (
Object
)config
(Optional) Custom filter configuration regarding lines/services
mvg.getDepartures(70).then((departures) => {
console.log(departures);
});
mvg.getDepartures(70, {
footway: false,
bus: true,
ubahn: true,
sbahn: true,
tram: false,
zug: true
}).then((departures) => {
console.log(departures);
});
{
"servingLines": [
{
"destination": "Fürstenried West",
"sev": false,
"partialNet": "mvv",
"product": "UBAHN",
"lineNumber": "U3",
"divaId": "21003"
}
],
"departures": [
{
"departureTime": 1522406360000,
"product": "UBAHN",
"label": "U3",
"destination": "Moosach",
"live": true,
"lineBackgroundColor": "#ef8824",
"departureId": 810156845,
"sev": false
}
]
}
Fetches available vehicles (i.e. rental bikes and car sharing offerings) for a specific location
- (
String
|Number
)latitude
(Required) Latitude - (
String
|Number
)longitude
(Required) Longitude
mvg.getVehicles('48.1373968', '11.5732598').then((vehicles) => {
console.log(vehicles);
});
{
"type": "vehicleDataNearby",
"bikeStations": [
{
"type": "bikeStation",
"name": "Universität",
"location": {
"type": "location",
"latitude": 48.1495361328125,
"longitude": 11.580649375915527
},
"availableBikeCount": 1
}
],
"bikes": [
{
"type": "bike",
"name": "96947",
"location": {
"type": "location",
"latitude": 48.1495361328125,
"longitude": 11.580649375915527
}
}
],
"carStations": [],
"cars": []
}
Fetches streets and POIs matching a specific query
- (
String
)query
(Required) Search query
mvg.getLocations('Leopold').then((locations) => {
console.log(locations);
});
[
{
"type": "address",
"latitude": 48.170596,
"longitude": 11.585905,
"place": "München",
"street": "Leopoldstraße",
"poi": false
}
]
Fetches details for all plans/services
mvg.getPlans().then((plans) => {
console.log(plans);
});
[
{
"fileSize": "1036887",
"md5Hash": "ad87578d4d375fcebdb9f6a637351936",
"planId": "SCHNELL",
"title": "{\"de\":\"Schnellbahnnetz\",\"en\":\"Suburban train network\",\"by\":\"Schneibahnnetz\"}",
"validFrom": "2017-12-10",
"provider": "MVV",
"sortIndex": 1,
"minLatitude": 0,
"maxLatitude": 0,
"minLongitude": 0,
"maxLongitude": 0,
"rotationAngle": 0,
"titles": {
"de": "Schnellbahnnetz",
"en": "Suburban train network",
"by": "Schneibahnnetz"
}
}
]
Fetches details for a specific plan/service
mvg.getPlan('SCHNELL').then((plan) => {
console.log(plan);
});
{
"fileSize": "1036887",
"md5Hash": "ad87578d4d375fcebdb9f6a637351936",
"planId": "SCHNELL",
"title": "{\"de\":\"Schnellbahnnetz\",\"en\":\"Suburban train network\",\"by\":\"Schneibahnnetz\"}",
"validFrom": "2017-12-10",
"provider": "MVV",
"sortIndex": 1,
"minLatitude": 0,
"maxLatitude": 0,
"minLongitude": 0,
"maxLongitude": 0,
"rotationAngle": 0,
"titles": {
"de": "Schnellbahnnetz",
"en": "Suburban train network",
"by": "Schneibahnnetz"
}
}
- 1.0.1
- Implement code style fixes
- 1.0.0
- Initial version
This project consumes the official MVG Fahrinfo app API and is not related, acknowledged, or sponsored by MVG or SWM. Use at your own risk.
Copyright (c) 2018 Thomas Rasshofer
Licensed under the MIT license.
See LICENSE for more info.