This scriptable based iOS widget gives you the opportunity to have your most important MVG (Münchner Verkehrsgesellschaft) always available and up to date so that you can quickly check when the next Bus, UBahn, SBahn or Tram leaves.
The development is ongoing so drop me a note if you have ideas for future changes.
- Show next connections between two stations in MVG area
- Show next departures for specific stations in MVG area
After you have the main widget running it is automatically updating the real widget code every day if there are changes on the main branch in the Github Repository. This could be new functions or bug fixes. In the future I will also provide a main.js which does not update the widget.js code. You can chose that if you have security concerns.
The preparation step only needs to be done once. Afterwards the widget can be used multiple times.
-
Install the Scriptable app on your iPhone via the App Store. Link to Scriptable app: https://apps.apple.com/de/app/scriptable/id1405459188
-
Take your iPhone and go to: https://raw.githubusercontent.com/froehr/train-tracker/main/main.js
This is the code for the widget to run on your phone. Copy EVERYTHING from the first till the last line.
-
Open the Scriptable app on your iPhone and tap the + Button in the top right corner to create a new script.
-
Paste the COMPLETE code from the link in step 2 into the editor and click done in the top left corner.
-
The new script should be available in the overview now and named Untitled Script. By clicking it a preview of the widget should be shown.
-
Rename the new script by long-clicking it and choosing rename. Name the script TrainTracker.
There are three decisions you have to make:
-
Widget Size
-
Widget Content
-
Widget Station(s)
There are different widget sizes that work but not all functionality is available in all sizes due to size constraints.
Widget Size | Available on | Single Connection | Double Connection | Single Departure | Double Departure | Four Departures | Line Messages |
---|---|---|---|---|---|---|---|
Small | iPhone, iPad | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
Medium | iPhone, iPad | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ |
Large | iPhone, iPad | ✅ | coming soon | ✅ | ✅ | ✅ | ❌ |
Extra Large | iPad | ✅ | coming soon | ✅ | ✅ | ✅ | coming soon |
As already presented above there are different things a widget can show. These are the possibilities:
Name | Function Key | Explanation | Implemented |
---|---|---|---|
Connection | CONNECTION | Showing the next connections between two defined stations. | ✅ |
Departure | DEPARTURE | Showing the next departures starting from a defined station. | ✅ |
Line Messages | MESSAGE | Showing messages related to as specific line. | ❌ |
To specify a station to use it in this widget you need the global identifier that the MVG uses to tag their stations. To get the global identifier for your station follow these steps:
-
Go to https://www.mvg.de/api/bgw-pt/v3/locations?locationTypes=STATION&query=SEARCH_PATTERN and replace SEARCH_PATTERN with the name of the station you are looking for.
-
You will receive a long list with results. Only those which have type set to STATION. Easiest way is to search for those by
Crtl+F
. When you have found the station you are looking for copy the globalId. -
Repeat this process for as many stations as you need for your widget setup.
It is possible to limit the types of transportation for departures and connections. If you don't specify anything all transportation types will be shown in the results. The possibilities to filter for are BAHN, UBAHN, TRAM, SBAHN, BUS and REGIONAL_BUS.
The widget needs to know what it is supposted to be displaying. To define that you need to set a parameter string in its configuration. This step is explained in section 3.4. First we need to create this parameter string. The format of this string is JSON.
- Widget showing one connection
{
"functionKey": "CONNECTION",
"connections" : [
{
"originId": "de:09162:1110",
"destinationId": "de:09162:2",
"transportationTypeFilter": "UBAHN,TRAM,SBAHN"
}
]
}
- Widget showing two connections
{
"functionKey": "CONNECTION",
"connections" : [
{
"originId": "de:09162:1110",
"destinationId": "de:09162:2",
"transportationTypeFilter": "UBAHN,TRAM,SBAHN"
},
{
"originId": "de:09162:2",
"destinationId": "de:09162:1110"
}
]
}
- Widget showing the departures at a single station
{
"functionKey": "DEPARTURE",
"departures": [
{
"originId": "de:09162:2",
"transportationTypeFilter": "UBAHN,TRAM,SBAHN"
}
]
}
- Widget showing the departures at two stations
{
"functionKey": "DEPARTURE",
"departures": [
{
"originId": "de:09162:1110",
"transportationTypeFilter": "BAHN,UBAHN,TRAM,SBAHN,BUS,REGIONAL_BUS"
},
{
"originId": "de:09162:2"
}
]
}
- Widget showing the departures at four stations
{
"functionKey": "DEPARTURE",
"departures": [
{
"originId": "de:09162:1110",
"transportationTypeFilter": "BAHN,UBAHN,TRAM,SBAHN,BUS,REGIONAL_BUS"
},
{
"originId": "de:09162:2",
"transportationTypeFilter": "BAHN,UBAHN,TRAM"
},
{
"originId": "de:09162:13",
"transportationTypeFilter": "BAHN,BUS,REGIONAL_BUS"
},
{
"originId": "de:09162:524"
}
]
}
After the preparation step and creating your parameter string the widget can be put onto the homescreen. You can even create multiple widgets with configurations of your choice.
-
Go back to your iPhone's homescreen to place the new widget on it.
-
Long press the homescreen (not an app) until the little + appears in the top left corner and all apps are wobbling around.
-
Tap the plus and chose Scriptable from the list. It will be somewhere close to the end of the alphabetical list.
-
Choose the widget size you like and that is supported for the function you have chosen and click Add Widget.
-
An empty widget has been placed on your homescreen now.
-
While it is still wobbling tap it and choose the script that should be executed. Choose the script TrainTracker that you've just created in the preparation phase.
-
Copy the parameter string that you prepared earlier and paste it into the Parameter field.
-
Click Ready. Your MVG Widget should be ready to use now.
If you have feedback of any kind or ideas for new features please open an issue and describe what you like to see. I would also appreciate feedback how it runs on your type of iPhone as I only have an iPhone 13 mini and can't test on other screen sizes.