PitStopper can take a track you recorded, or one you drew in another app, match it to the roads and paths on OpenStreetMap, and give it turn-by-turn instructions: a "turn left" where you turn left, a road name to listen for, a roundabout exit. Apps like Cruiser and Locus Map read those instructions from the GPX file and speak them as you ride or walk.
The hard part is deciding where they go. Leave one out and you miss a turn; put in too many and people stop listening, which is worse.
How our own rules grew
Our first version worked from the shape of the line. Wherever the track bent by more than about 25 degrees, that was a turn. That produces a cue on every bend of a country lane, so we added a rule: a bend on the same road is not a turn. Then a rule for roads with no name, where "same road" has to mean the same OpenStreetMap way. Then one for cycle paths that share a name with the street beside them, one for forks where every road has the same name, one for short jogs across a road, one for hairpins, one for u-turns, and one for staggered junctions.
Each rule came from a real file and fixed a real problem. By November the turn code was a thousand lines long and had been changed 27 times since September, and each change could quietly undo an earlier one.
Then one of our users, an experienced Cruiser rider in Belgium, sent us a short walk in Madeira. Another planner gave it two turn instructions. We gave it sixteen. Most of ours were switchbacks: a mountain path zigzagging uphill, every hairpin announced as a sharp right, though there was nowhere else to go. Another was on a private track the path follows, which we had dropped from the map entirely, so the walk looked as though it left the map there and every bend became a turn.
We fixed both, but by then it was clear what most of our rules were doing: using angles and road names to work out whether the rider had a choice. At a junction you can go the wrong way, so you need an instruction. On a bend with nowhere else to go, you can't, and you don't.
Looking at what already exists
Before writing yet another version ourselves, we looked at how the established routing engines handle it. Valhalla, OSRM and GraphHopper can all match a track to the roads and give it instructions, but each would have meant running another routing server worldwide, and replacing a matcher that already works well.
We already run BRouter for route planning, it is MIT licensed, and people who use our files in Cruiser and Locus hear BRouter's instructions every day anyway. Its VoiceHintProcessor decides where a route gets a "voice hint". In short:
- It looks at the other ways at each junction, the ones the route does not take. BRouter calls them "bad ways".
- A junction gets an instruction when another way runs clearly straighter than the one taken, when another way is a more important road, or when two ways fork close together ahead.
- The wording depends on those other ways too. A 90-degree turn becomes a sharp turn if another road leaves at a gentler angle, and a gentle split between two roads that both go ahead becomes "keep left" or "keep right".
- A bend with no other way to take gets nothing.
BRouter's issue #332 covers our case almost exactly: someone wanted BRouter's hints on a track BRouter hadn't planned. It explains why a cycle path that crosses a string of small roads gets "continue" at each one, and what to change.
How BRouter's approach differs from ours
| Our original rules | BRouter's voice hints | |
|---|---|---|
| Where it looks | every bend in the line, measured over 20 metres | only at junctions, where other ways meet the route |
| What makes an instruction | the line turns by 25 degrees or more, unless an exception says otherwise | another way could be taken by mistake: it runs straighter, it is a more important road, or it forks close by |
| Same road or not | guessed from road names, then from OpenStreetMap way numbers, with exceptions for paths and forks | not needed: a bend with no other way to take is never a question |
| Which instruction | from the angle of the bend alone | from the angle compared with the other ways: a turn can become sharp, slight, or "keep left" depending on what else leaves the junction |
| Road importance | not used | every road type has an importance, so leaving a main road for a lane is treated differently from the reverse |
| Instructions close together | kept the sharpest, then special cases for staggered junctions | merged by rules that look at the distance between them and what each one is |
Put simply, our rules found every bend first and then needed exceptions to throw most of them away. BRouter only looks where there is a choice to make, so it never finds those bends in the first place.
What we took, and what we changed
We ported VoiceHintProcessor to JavaScript, keeping its structure and the names of its conditions so that we can follow changes upstream. It works on the same information BRouter has: our matcher already knows, at every junction on the line, which ways meet there. We added an importance level for each road type, taken from BRouter's trekking profile.
Each change is listed, with the reason for it, at the top of the code. Here they are in plain terms.
Changes because a track is not a planned route. BRouter puts hints on a route it has just worked out itself. We put them on a line someone recorded or drew. That line wobbles, hops onto cycle tracks beside the road, and is sometimes walked where bikes and cars can't go.
- No "continue" while you stay on the same kind of way. From issue #332: a cycle path beside a main road should not say "continue" at every side road.
- Unclassified roads count as minor. BRouter's trekking profile ranks them close to main roads, which caused those "continue" cues on cycle paths.
- Two opposite turns close together say nothing. A matched line often steps sideways from a road onto its cycle track and back, a left and a right within a few metres. BRouter treats such a pair as "continue"; we drop it.
- A short link counts as a turn. Where a path meets a track and leaves it again 20 metres later, the turn is said at the junction, even if the mapper drew the corner on the link rather than at the junction. Only where another way ahead could be taken instead: a road curving past a side road behind it is just a curve.
- A one-way road against you still counts as a way you could take. The track may be a walker's, and a road that carries straight on can be taken by mistake whichever way its traffic runs.
Changes to match what our reviewers told us.
- "Something straighter" means clearly straighter. We use BRouter's older definition, where another way has to be at least 20 degrees straighter. The current one announces a road's own bend wherever a footpath leaves it.
- A side road that rejoins the route is not a choice. Where a side road is the short side of a triangle and meets the route again a few metres on, either way leads to the same place, so it no longer triggers an instruction on its own. Our Belgian reviewer's three "no turn needed" verdicts on his home roads set this one.
- Leaving a road that carries on is a turn. BRouter does not know road names. Where the road you are on carries on under its own name and the route leaves it for another, that is now an instruction, even when the other road is minor.
- Straight on between two forks says nothing. Where the route goes dead straight with a road forking off gently on each side, BRouter says "keep right" for the one on the left whatever is on the right. We say nothing: you carry on.
- The bands for slight and normal turns follow PitStopper's level-of-detail setting rather than fixed angles. "Fewer" drops slight turns and keep left/right altogether; "More" brings back BRouter's "continue" where you cross a bigger road.
Two small corrections. In two places the code looked lopsided or let a value carry over from one check into the next: "keep left" is now protected the same way "keep right" already was, and a way skipped as leading backwards no longer makes a gentle bend look like a fork. If these turn out to apply in BRouter too, we'll offer them back.
We left out motorway exits, car-only merges, give-way signs and BRouter's per-profile costs. Most people use our turn files on foot or on a bike, and at that stage we have no routing profile to go on.
Some of our own code stayed, for things BRouter never needs because it plans routes rather than reading tracks:
- Stretches with no map. Where a track leaves the mapped paths we only have its shape, so only a sharp bend becomes a turn.
- Roundabouts. The exit number goes into the instruction, as
roundabout_e2for the second exit, which is what Cruiser and Locus expect. - Real u-turns, told apart from switchbacks by whether the line comes back along itself.
- Hairpin warnings, for anyone who wants sharp bends announced. They are now off by default.
Before and after
Here are four places from our test routes. In each map the old file is on the left and the new one on the right, and each circle is an instruction.
A walk up a Madeira hillside. The path zigzags uphill in a run of tight hairpins, with nowhere else to go at any of them.
- Before: a "sharp right" at every hairpin; 16 instructions for a 13 km walk, where another planner gave 2.
- After: nothing on the hairpins. An instruction only where the path meets another path or track, such as the right turn off a short stretch of track at 9.3 km.

A country road in Belgium that just bends. Twice in its first two kilometres the road turns a corner, and you simply follow it round.
- Before: "turn left", twice, while you stay on the same road.
- After: nothing. Both of us who reviewed it, one of whom rides these roads, said no instruction was needed.

A fork on Crete. A route drawn in Kurviger, where the road splits into two that both carry on ahead.
- Before: nothing at the fork, so you had to guess.
- After: "keep left".

A cycle path beside a road in the Netherlands. The route follows a cycle path for kilometres, alongside a road with side roads every few hundred metres.
- With BRouter's rules exactly as they are: "continue" at 31 of those side roads.
- With the change from issue #332: 3, only where the cycle path becomes a different kind of way.
How we checked it
We built a test set of 26 routes: recordings and drawn routes, walks, rides and motorbike tours, in Belgium, the UK, the Pyrenees, Mallorca, Madeira, the Netherlands, Paris, Tokyo and Mexico City. For every route we put each instruction that changed on a map, with the stretch of route leading into it, and marked it right or wrong by eye.
Two of us went through about 250 of those changes: me, and the user who sent the Madeira walk, who knows the Belgian roads in the set. We judged about nine in ten of them right. Most of the rest (an obvious carry-on that still got an instruction, two turns close together merged into one) became tests for a last round of fixes.
It still gets some wrong. As that user put it, in some traditions only the highest power may claim to be flawless. If an instruction is wrong for your ride, you can change or remove it by hand in PitStopper.
Thank you, BRouter
BRouter's rules were written and refined over years by people who know this problem far better than we do. In a few days they did what our own rules hadn't managed in months. We had started from scratch with not much experience, and our rules showed it.
So, thank you to Arndt Brenschede and everyone who has contributed to BRouter, and to the people in issue #332, whose discussion pointed us at the two changes we needed. PitStopper's turn instructions are built on your work, and the code says so.
