Routes without signal
Timetables, routes, and fares ship inside the app, so planning still works when the signal drops on the train. Here is how it works.
- Published
- Reading time
- 3 min read
- Project
- RuteKita
- Topics
- Connection scan, GTFS, Offline, React Native
The data ships in the app
RuteKita never reads GTFS at runtime and uses no server to plan routes. Before a release, Python scripts turn official sources into compact JSON: the KRL timetable from KAI Commuter's timetable PDF with track geometry from OpenStreetMap, TransJakarta from its official GTFS (with Transjakarta's written permission), and MRT and LRT from their operators' timetables.
The result is bundled with the JavaScript. The TransJakarta data, the largest, is about 1.4 MB for 240 routes: stops are kept as short rows, and route lines as integer coordinate deltas that are expanded when the app loads. Because it ships in the bundle, a data update can go out as an OTA update without a new APK.
A connection scan, once per number of trains
For station-to-station trips, every train trip is cut into hops between two stations, and all hops are sorted by departure time. The algorithm is a connection scan: the starting point is found with a binary search, hops are scanned in order, and every station keeps its earliest arrival.
The scan runs once for each number of trains, from one to four. So a journey with fewer changes is found next to the fastest one, and wins when it arrives no more than 6 minutes later per extra train. A platform change counts as 4 minutes.
MRT, LRT, and KRL do not share stations, so changing between them is a walk. The straight-line distance is multiplied by 1.3 for streets, crossings, and skybridges, at an unhurried 75 metres a minute.
A bus at each end, trains in the middle
Combined TransJakarta routes are limited on purpose: at most one bus at each end, with trains in the middle. From each end, the four best ways into a station are tried, and each is handed to the same train planner. A halte counts as connected to a station when it is within 400 metres in a straight line.
Bus times are estimates. The wait is half the headway, and the ride time comes from the GTFS timetable. On stretches of 3 km or more with no stop, such as toll roads, the time is recomputed at 40 km/h, because the source data times every stretch at about 13 km/h. Routes that use estimates are marked in the app.
Fares from official tables
KRL fares come from KAI Commuter's station-to-station fare table, not from coordinate distances. Station pairs missing from the table show as unknown rather than guessed. TransJakarta uses the per-corridor fare from GTFS plus the early-morning fare rule from the Jakarta government site, and MRT and LRT use their operators' station-to-station tables.
The JakLingko fare cap is only shown as a conditional note next to the normal total, because KRL and LRT Jabodebek are not part of that package.
Train positions from the timetable
Trains on the map do not use GPS. Every second, the app finds the last station each trip has passed, allows a dwell of at most 30 seconds, then places the train proportionally along the track line toward the next station. Trips that run past midnight are included.
What is not offline yet
The base map still needs the internet, because its tiles come from OpenFreeMap. An offline map pack for Greater Jakarta has been researched, about 65 to 76 MB up to zoom 14, but not built. Without signal, timetables, routes, fares, and train positions keep working; only the street background goes.
The routing and fare engines are plain TypeScript functions with no ties to the UI, so they can be tested directly with node --test.