+
A route line is what the map draws for a route between its stops. Since 26 November 2026, Malaysia Transit and SG-JB Transit draw their Enhanced route lines from OpenStreetMap, the open map of the world, instead of Google Directions. Buses are matched to the roads with pfaedle, an open-source tool from the University of Freiburg made for exactly this job, and trains follow the railway track by a method of our own that also finds stations a timetable puts in the wrong place.
Riders read a route from its line. Most of the timetables we show don't draw one that follows the roads, and the service that used to draw them for us came with terms our maps can't meet.
A route line is the path the map draws for a bus or train route between its stops. Riders use it to see which roads a bus takes, where it turns and where to wait for it, and the apps draw each ride of a planned journey along it. Both products offer two styles, switched on the map under Route Style:
The stops joined by straight lines, or the operator's own line where its timetable has one. Always available, and honest about what the timetable says.
The route along the roads it really takes, and trains along their track. Labelled "✓ Enhanced along OpenStreetMap" where the line comes from this work.
Timetables in the GTFS format may carry each route's path (the optional shapes.txt file), but most of the ones we show don't carry one that follows the roads:
Prasarana's feeds (Rapid KL's buses and trains, the MRT feeders and Rapid Penang), BAS.MY's for Johor Bahru and Melaka (5 to 20 points per stop) and Rapid Kuantan's already have good lines of their own, and keep them. The server uses an Enhanced line where a timetable's own is too sparse to follow the roads: fewer than 1.5 points per stop, no line at all, or a KTM train.
Until 26 November 2026, Enhanced lines came from Google Directions, in three ways:
Google's Service Specific Terms say Directions results "must not" be used "in conjunction with a non-Google map" (section 4.2). Our websites draw with Leaflet on an OpenStreetMap map, and the apps with MapLibre: neither is Google's.
Only latitudes and longitudes may be cached, for up to 30 days (section 4.3), and the general terms forbid storing Google's content or making new content from it (section 3.2.3). Lines saved into timetables, or cached for good, did both.
A directions service finds its own best way between each pair of stops: it doesn't know which roads the bus takes. Where a stop sat a little off the road, Google's line sometimes swerved onto another road to reach it.
Every line asked for is a billed request (US$5.00 per 1,000 Directions calls after 10,000 free a month), and the risk was larger than the bill: breaking the terms lets Google suspend the account's Maps services, all at once.
On 26 November 2026 the first plan was to fall back to Basic lines everywhere, until we asked whether Enhanced lines could come from somewhere other than Google. These were weighed:
| Option | How it works | Verdict |
|---|---|---|
| Basic lines only | The stops joined up, or the operator's line | Allowed and free, but gives up the road-following lines riders had |
| pfaedle | Matches whole timetables to OpenStreetMap's roads and railways ahead of time | Chosen Made for exactly this, open source, offline, about a minute per timetable |
| MOTIS's route shapes | The journey planner can work out lines for trips without one from its own street routing (its route_shapes setting) | Not yet running when the lines were needed, and it would tie the route views to the planner. The planner now draws its rides along pfaedle's lines instead |
| Valhalla | An open-source router with a bus profile, which can snap points to the roads when a line is asked for | One more service to run and call while riders wait, as Google was. Building lines ahead of time is simpler, and each can be checked before anyone sees it |
| Google Directions | Directions through the stops | Not allowed on our maps or to keep (section 3) |
We trialled pfaedle on the server first (section 11). Its first lines looked better than Google's had, and they became the new Enhanced the same day.
Buses and trains are drawn by two methods, on the same OpenStreetMap data, into the same kind of file. Both run ahead of time, so riders never wait on them.
OpenStreetMap is the free, editable map of the world, made by volunteers and published under the Open Database Licence. Besides drawing the base map of both products, it describes everything a route line needs:
| What | How OpenStreetMap records it | Used for |
|---|---|---|
| Roads | highway=* ways, from motorways to service roads, with oneway and access tags | Bus lines |
| Turn rules | type=restriction relations (no right turn, only straight on…) | Bus lines |
| Railway track | railway=rail ways, with service=siding, yard, crossover or spur for side track | Train lines |
| Stops and stations | Bus stops, platforms, stop positions and stations, with their names | Placing stops; station positions |
pfaedle is a free, open-source tool that gives a GTFS timetable its route lines by matching every trip to OpenStreetMap. It comes from the Chair of Algorithms and Data Structures at the University of Freiburg in Germany (Professor Hannah Bast's group), where Patrick Brosi wrote it and still develops it. It first appeared in 2018, with the paper "Sparse Map-Matching in Public Transit Networks with Turn Restrictions" (Bast and Brosi, ACM SIGSPATIAL 2018), and its method is the first part of Brosi's doctoral thesis, Automated Generation of Transit Maps (2022). It is written in C++ and published under the GNU General Public Licence, version 3.
It reads a whole GTFS feed and works from what a timetable already has: each trip's stops in order, their positions and names, and their times.
Its settings cover buses and coaches, trams and subways, trains, ferries, gondolas and funiculars, each matched only to the kind of way it runs on.
It writes the lines into the timetable's shapes.txt. Nothing is asked of any service while riders use the apps.
In the thesis it matched every trip in Germany in 8.5 minutes (not counting reading the map), and got 90% of trips right on at least nine hops in ten, against 84% for the usual distance-based method, with lines 6.9 m from the true path on average.
Map matching usually starts from a GPS trace: a position every second or so, close together. A timetable gives far less: only the stops, often hundreds of metres apart. Between two stops many paths are possible, and the job is to pick the one the bus really takes. pfaedle treats this as a hidden Markov model, the standard tool for map matching: the stops are what is observed, and where each stop really sits on the network is hidden. With the settings it ships with, it works like this:
One script, scripts/osm-lines/build.mjs, builds every line. It runs on the server beside the live apps, so it is careful with memory.
| Step | What happens |
|---|---|
| 1. Pick the timetables | From the service areas the apps serve: every BAS.MY city but Kuantan, Bas Muafakat Johor, Causeway Link, City Public Link S19, the Singapore cross-border buses and, given LTA DataMall's routes, every Singapore bus service; for trains, KTMB, KLIA Ekspres and SRT's shuttle. A new BAS.MY city is picked up at the next build. |
| 2. Find the trip patterns | A pattern is one distinct sequence of stops: a route, a direction, a variant. Every trip with that sequence shares its line, so 1,338 patterns stand for all the trips. The stops are the ones the server lists, after it merges a timetable's stops into places, so the line's stop ids are the ones the apps receive. |
| 3. Write a small timetable | One trip per pattern, with its stops and times, as a GTFS folder for pfaedle. |
| 4. Run pfaedle | In a container from an image pinned to one exact build, matching buses only and every trip afresh. Each run is capped at 3 GB of memory and 2 CPUs at low priority, one at a time; none starts with less than 3.5 GB free, and a run is stopped after 45 minutes. |
| 5. Check each line | The quality gate below. A line that fails is not kept, and the server goes on showing the timetable's own line for that pattern. |
| 6. Pin the stops | Each stop is pinned to its point on the line, in the stops' order. A stop's choices are its nearest points on up to 8 pieces of the line and the nearest point of every pass the line makes within 250 m of it: a loop that starts and ends at its terminal passes it twice, and the first stop belongs on the first pass even where the nearest pieces all lie on the last. A line that can't pass its stops in order isn't kept. The server can then cut the line between any two stops. |
| 7. Simplify and store | Points closer than 2 m (buses) or 4 m (trains) to the simplified line are dropped, as the eye can't see them; stop points are always kept. Each line is stored as an encoded polyline (to about a metre), in one JSON file per timetable with its build time, the map data's date, the credit and the licence. |
| 8. Report | Each timetable's patterns kept and not kept, and why; lines with a straight piece over 1.5 km (a road pfaedle couldn't follow there); and the stations left out of train lines. |
A line is kept only if it passes its stops in order, every stop is within 200 m of it, and, for patterns longer than 300 m, it is between 0.7 and 3 times as long as its stops joined up. The trial's worst kept cases were a stop 115 m from its line (a pole recorded well off the road) and a two-stop route 2.5 times its straight length, because its road really goes round. A line that is too short has cut a corner; one that is far too long has wandered.
pfaedle draws a train's line through every station, as it should. But KTMB's timetable places some stations well away from the railway, and a station in the wrong place pulls the line off the track: out to Sedenak, 509 m from the railway between Layang-Layang and Kulai; out to Kalumpang, placed about 7 km from the real station; and zigzagging to East Coast halts several kilometres off the line. So trains are drawn by a method of our own (scripts/osm-lines/railPaths.mjs), on the railway track pfaedle extracts from the map:
Left-out stations stay in the timetable and on the map; only the drawn line doesn't bend to them, and the server lists them with the line (skippedStops). Where stations are placed correctly, this method and pfaedle give the same line: on Komuter Utara both sit on the railway, and the track method places stations a few metres closer (17 m and 28 m on average, against 22 to 32 m). Long hops are real track, not errors: Ipoh to Kuala Kangsar is 51.7 km by rail for 25.3 km in a straight line, and Dabong to Kuala Krai 55.0 km for 27.3 km. Two settings were tuned on such cases: at 2 times the straight distance the method wrongly dropped Ipoh and Kuala Krai, and without the 5-to-1 weight lines started 261 m from Dabong and 198 m from Gua Musang, joined through a short station siding.
pfaedle was tried in three rounds on 26 November 2026 before anything went live, on the same server and with the same caps as the build uses today.
| Timetable | Time | Peak memory | Trips matched | Stop to line |
|---|---|---|---|---|
| Singapore cross-border buses | 73 s | 437 MB | 1,565 of 1,565 | 11.4 m |
| Causeway Link | 73 s | 446 MB | 1,015 of 1,015 | 9.6 m |
| BAS.MY Kangar | 48 s | 353 MB | 344 of 344 | 6.5 m |
| KTMB (rail) | 36 s | 131 MB | 265 of 265 | 20.1 m |
Stop to line: the median, over a timetable's patterns, of the average distance from each stop to the line. Most of each run (about 65 seconds) is spent reading the map file; the matching itself takes about a second per timetable.
| Timetable | Time | Peak memory | Patterns | Stop to line |
|---|---|---|---|---|
| Alor Setar | 61 s | 498 MB | 26 | 6.7 m |
| Kota Bharu | 55 s | 397 MB | 32 | 8.4 m |
| Kuala Terengganu | 49 s | 282 MB | 17 | 8.1 m |
| Kuching (with stand-in times) | 48 s | 293 MB | 22 | 6.6 m |
| Ipoh | 55 s | 328 MB | 29 | 11.2 m |
| Seremban A | 61 s | 489 MB | 19 | 8.0 m |
| Seremban B | 73 s | 562 MB | 22 | 8.1 m |
Ipoh's figure is the highest because its feed lists a separate pole for every route at shared stops. Komuter Utara's lines were good too: all 40 straight pieces over 2.5 km stay within 6 m of the real track, half within 1 m, because pfaedle draws straight track with few points.
| KTMB timetable | Time | Stations | Lines | Stations left out | Straight gaps |
|---|---|---|---|---|---|
| Malaysia Transit's copy | 17 s | 184 | 45 | 23 | 0 |
| data.gov.my's live feed | 54 s | 156 | 86 | 14 | 0 |
Every train line followed the railway with no straight gaps; each straight piece over 2.5 km is a single piece of mapped straight track (the longest, 5.8 km, crosses the Perlis and Kedah paddy belt). Kept stations sit within 150 m of their line, except two whose recorded positions are that far from the track.
| Timetable | Method | Patterns kept | File |
|---|---|---|---|
| Singapore's buses (LTA DataMall) | pfaedle | 802 of 802 | 943 KB |
| KTMB (every KTM service) | Track | 121 of 121 | 417 KB |
| BAS.MY Melaka | pfaedle | 66 of 66 | 113 KB |
| Bas Muafakat Johor | pfaedle | 57 of 57 | 51 KB |
| BAS.MY Johor Bahru | pfaedle | 45 of 45 | 66 KB |
| Causeway Link | pfaedle | 36 of 36 | 38 KB |
| BAS.MY Kota Bharu | pfaedle | 32 of 32 | 70 KB |
| BAS.MY Ipoh | pfaedle | 30 of 30 | 50 KB |
| BAS.MY Alor Setar | pfaedle | 27 of 27 | 33 KB |
| BAS.MY Kangar | pfaedle | 23 of 23 | 40 KB |
| BAS.MY Kuching | pfaedle | 23 of 23 | 31 KB |
| BAS.MY Seremban B | pfaedle | 22 of 22 | 53 KB |
| BAS.MY Seremban A | pfaedle | 18 of 19 | 33 KB |
| BAS.MY Kuala Terengganu | pfaedle | 19 of 19 | 32 KB |
| Singapore cross-border buses | pfaedle | 6 of 6 | 10 KB |
| KLIA Ekspres and KLIA Transit | Track | 4 of 4 | 5 KB |
| Causeway Link AA1 | pfaedle | 2 of 2 | 2 KB |
| City Public Link S19 | pfaedle | 2 of 2 | 3 KB |
| SRT Padang Besar–Hat Yai | Track | 2 of 2 | 2 KB |
| 19 timetables | 1,211 pfaedle, 127 track | 1,337 of 1,338 | 1.94 MB |
Built on 26 November 2026 from OpenStreetMap data until 17 November 2026 (SRT's railway: an extract of 28 July 2026); on 27 November the bus lines' stops were pinned again, as step 6 of section 8 describes, the cross-border buses' lines built again on LTA DataMall's stop positions, and those and Singapore's built again with the 160, the 950 and the 170X drawn out to JB Sentral and back (section 10). One line doesn't pass its stops in order and isn't kept: Seremban A's Desa Rhu loop. KTMB's file serves all 11 KTM services in the apps, from Komuter Klang Valley to Shuttle Tebrau and the Intercity trains to Kota Bharu. BAS.MY Johor Bahru's and Melaka's own lines already follow the roads, so their route views keep them.
| Google Directions (before) | OpenStreetMap (now) | |
|---|---|---|
| On our own maps | Not allowed (section 4.2) | Allowed, with the credit |
| Keeping them | Coordinates only, for 30 days | Ours to keep, and to share under the same licence |
| Which roads | Google's own best way between each pair of stops | The quickest way through all the stops in order, weighing each stop's distance, road class, turns and mapped bus routes |
| A stop set back from the road | Could swerve onto another road to reach it | Pinned to the road beside it; a line too far from any stop isn't kept |
| Trains | Through every station, even one placed off the line | Along the track, leaving out stations placed off it, and reporting them |
| Fit with the map | Google's road geometry over an OpenStreetMap map | The same roads the map draws |
| Cost | US$5.00 per 1,000 requests after 10,000 free a month | Nothing per line; about 20 minutes of our server per rebuild |
| Fresh roads | Google's current map | As fresh as the extract: rebuilt every month or two |
| If it fails | No line, or a line that bends wrong | The quality gate falls back to the timetable's own line |
On ordinary roads the two are very close: CW2's new line is 2.5 m from Google's on average. The difference shows where it matters to riders: at stops set back from the road, at terminals and interchanges, and on trains whose timetable puts a station in the wrong place.
Drawing lines carefully is also a close check of the timetables. These findings are worth sending to KTMB and data.gov.my, and are listed with every build:
KTM stations off the railway. More than 5 km off: Mela, Sg Mengkuang Baru, Kuala Gris, Kemubu, Sri Mahligai, Kalumpang (placed near Lembah Beringin), Tembeling and Padang Piol. Closer in: Sri Bintang 4.5 km, Pahi 4.4 km, To' Uban 2.9 km, Aur Gading 1.6 km, Sri Jaya 1.4 km, Kg Berkam 1.1 km, Bertam 666 m, Sedenak 509 m, Dura 412 m, Sungai Temau 341 m and Holiday Plaza 307 m.
In the wrong place or order. "Mengkuang" is timetabled between Triang and Kemayan in Pahang but placed south of Kuala Krai in Kelantan, about 330 km up the line. Kubang Rusa and Teluk Gunong are listed in swapped order, and so are Kg Telang and Pdg Tungku.
Other timetable issues. On Kuching's Q11 to Q16 every stop has the same time (section 10). KTMB's live feed has no route lines at all, and codes its five Komuter services, Shuttle Selatan among them, as trams. The KTMB copy used in the trial had 8 stop times pointing at a station (37200) missing from its stop list, and 39 Komuter trips with no stops. BAS.MY's feeds, all but Johor Bahru's and Melaka's, have one line point per stop, and some poles recorded 40 to 115 m off the road. (Hat Yai is left out of KTM's lines only because the main extract stops at the border: not a timetable error.)
The lines are plain files in the server's code. The server reads them when it starts, and riders get them with no outside service in the way.
Lines are rebuilt when a timetable's trips change a lot, and every month or two for newer map data. The whole build takes about 20 minutes on the server:
Per timetable a run takes about a minute and under 0.5 GB of memory; extracting the railway for the train method takes 43 seconds at a 139 MB peak, and the track method itself seconds.
pfaedle: github.com/ad-freiburg/pfaedle (code, default settings and README, read 27 November 2026); H. Bast and P. Brosi, "Sparse Map-Matching in Public Transit Networks with Turn Restrictions", Proceedings of ACM SIGSPATIAL 2018, pp. 480–483, doi:10.1145/3274895.3274957; P. Brosi, Automated Generation of Transit Maps, doctoral thesis, University of Freiburg, 2022, chapter 2, "Map-Matching Schedule Data", doi:10.6094/UNIFR/228990.
OpenStreetMap: openstreetmap.org/copyright (credit and licence); the Open Database Licence 1.0, opendatacommons.org/licenses/odbl/1-0; Geofabrik's Malaysia, Singapore and Brunei extract, download.geofabrik.de/asia/malaysia-singapore-brunei.html; the Overpass API, overpass-api.de.
Timetables: data.gov.my's GTFS feeds (CC BY 4.0); LTA DataMall's bus routes and stops (Singapore Open Data Licence); the GTFS reference for shapes.txt, gtfs.org.
Google Maps Platform: Service Specific Terms (version of 24 November 2026), cloud.google.com/maps-platform/terms/maps-service-terms; Terms of Service, cloud.google.com/maps-platform/terms; pricing, developers.google.com/maps/billing-and-pricing/pricing (read 27 November 2026).
Malaysia Transit's own records: how the lines are built (docs/osm-route-lines.md), the builder (scripts/osm-lines/), the line files (data/osm-lines/, built 26 November 2026, the bus lines' stops pinned again on 27 November), and the pfaedle trial report of 26 November 2026, with its three rounds.