Start a project
Menu

BTV Transit

How BTV Transit decides when to tell you to get off

The rules behind one notification: how the app turns GPS into metres along a bus route, and the bug that sent “Your stop is next” three stops early.

BTV Transit is the studio’s iPhone app for Vermont buses. On a ride, its main job is one notification, “Your stop is next”, sent at the right moment. This post covers how the app picks that moment, and the bug that sent it too early until October.

Where the bus is, in metres

You tap the stop where you get off. From then on the app works in one unit: metres along the route. Each route’s shape comes from the operator’s timetable data, and each stop has its distance along that shape. Every GPS fix from the phone is projected onto the shape, which turns a latitude and longitude into one number, such as 4,212 metres along route 2.

The projection searches near the last position first, from 250 metres behind it to 800 metres ahead, so a route that passes the same street twice doesn’t make the position jump. A fix more than 45 metres from the route, plus up to 40 metres for the accuracy the GPS reports, doesn’t count. When the app is working out which bus you’re on, a route heading more than 75 degrees away from the direction the phone is moving is ruled out, so the bus going the other way on the same street isn’t taken for yours.

On the bus, at a stop, or between stops

Two speeds sort out the rest. You count as on board once the phone moves faster than 2.5 metres a second (about 5.6 mph, faster than a walk) from 30 metres before your boarding stop onward. You count as standing at a stop when you are slower than 1.5 metres a second and within 35 metres of one. Otherwise, the next stop is the first one more than 15 metres ahead.

The bug: three stops early

The first version sent “Your stop is next” once the bus was within 400 metres of your stop. On a rural route, with stops far apart, that worked. Where stops sit close together, 400 metres covered two or three of them, and the alert arrived that early.

Since 23 October the rule counts stops first. The alert goes when your stop is the next one and the bus is moving between stops. If the bus is standing at the stop before yours, it goes only when your stop is under 400 metres away; otherwise it waits for the bus to pull out.

The chime

The notification plays the two-tone chime a bus makes when someone rings for a stop, a 1.5-second recording bundled with the app, and is sent as a time-sensitive notification. It reads “Ring the bell for” and the stop’s name. Within 30 metres of the stop, or once past it, a second notification says you’re there.

When GPS loses the ride

Location can be switched off, or the signal weak on a rural road. So during a ride the app also schedules a notification for two and a half minutes before the bus is due at your stop, saying the stop is due in about two minutes. The due time uses the operator’s live prediction where there is one; a stop without one takes the delay of the closest earlier stop that has one, the way the operators’ own boards do. If GPS sends the real alert first, the scheduled one is cancelled. With no GPS fix, the ride screen counts stops off the same times.

All of it runs on the phone, and your location stays there. The case study covers the rest of the app.

Keep reading

All writing

Building something like this?