Start a project

How BTV Transit decides when to tell you to get off

How the BTV Transit app turns GPS into metres along a bus route to time one notification, and the bug that sent “Your stop is next” three stops early.

Baris TaskiranFounding engineer

On this page 5 sections
  1. Where the bus is, in metres
  2. On the bus, at a stop, or between stops
  3. The bug: three stops early
  4. The chime
  5. When GPS loses the ride

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. The app projects every GPS fix from the phone onto the shape. That 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. That way, 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, it rules out any route heading more than 75 degrees away from the direction the phone is moving. So the bus going the other way on the same street can’t pass for yours.

On the bus, at a stop, or between stops

Two speeds sort out the rest. From 30 metres before your boarding stop onward, you count as on board once the phone moves faster than 2.5 metres a second. That is about 5.6 mph, faster than a walk. 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. Counting stops instead of metres means the alert lands one stop ahead, whether the stops are close together in town or far apart on a rural road. 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. The app sends it 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

A rider can switch location off, and rural roads can have a weak signal. So during a ride the app also schedules a notification for two and a half minutes before the bus is due at your stop. It says 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 app cancels the scheduled one. With no GPS fix, the ride screen counts stops off the same times.

All of BTV Transit’s alert logic runs on the phone, and your location stays there. The case study covers the rest of the app.

Keep reading

All posts
  1. Adding an AI assistant to your website without it making things up

    How an AI chatbot for a small business website stays grounded in your own content, what to test before launch, and what to ask any vendor.

    AI

    4 min

  2. AI Automation for Small Businesses: 5 Safe Ways to Use It

    AI automation for small business without the hype: five jobs worth handing to AI, three that aren't, and the guardrails we use in our own tools.

    AI

    4 min

Your vision. Our solutions.

A few lines about the project and when it needs to ship is enough to start. Replies usually come within one business day.

Start a project