Theo Gieruc

Real-Time Bus Tracking for My Stop in Lausanne

I live near the Censuy stop in Renens. Three TL bus lines pass through: 25, 32, and 33. The official TL app shows departure times, but I wanted something I could glance at and immediately see where the buses actually are on the map, how far away, and whether they’re late.

So I built a dashboard that shows live bus positions animated along their routes, with a departure board on the side.

How It Works

The backend fetches real-time departure data from the transport.opendata.ch API. But the API only gives you departure times at stops, not GPS positions between stops. To show buses moving on the map, I had to compute trajectories.

Each bus route has a known sequence of stops with scheduled times (from GTFS data). When a bus departs a stop, I know its schedule for the remaining stops on the route. By interpolating between stops based on the current time vs. scheduled arrival times, I can estimate where the bus is right now as a fraction along the route geometry.

The route geometries themselves are snapped to actual roads using OSRM, so the bus dots follow real streets instead of straight lines between stops.

The frontend animates the bus positions using requestAnimationFrame, interpolating the trajectory waypoints in real time. The result: smooth-moving dots on a dark map, each colored by line number.

The Stack

  • Backend: Gleam (compiles to Erlang/OTP), using Wisp and Mist for HTTP
  • Frontend: SvelteKit with MapLibre GL on a CARTO Dark Matter basemap
  • Data: GTFS schedule data for route shapes, transport.opendata.ch for live departures
  • Hosting: Dockerized Gleam backend on my Proxmox homelab, frontend served by Caddy

The backend caches API responses for 60 seconds to avoid hammering the public API. Trajectory computation (matching departures to route geometries, deduplicating buses, interpolating waypoints) happens server-side so the frontend just receives a list of waypoints to animate.

Picking a Stop

The dashboard defaults to Censuy but you can search for any TL stop. Click the stop name at the top, type a station name, and the map flies to the new location with updated departures and bus positions.


Open the dashboard | Source code