Gas On Route: Cheap Fuel Along Your Route, Detour Included

Years ago I found out that the Spanish Ministry publishes the price of every petrol station in the country as open data, updated live. I started an app around it, got as far as a list of stations, and left it in a folder. This month I picked it up again with a better question: not “where is fuel cheap?” but “where along the way I’m already driving does it actually pay to stop?” The result is Gas On Route, now waiting for review on Google Play.

Gas On Route: a route from Madrid to Barcelona with the best pick

The idea: price is only half the cost

A station 3 km off the motorway can be 5 cents cheaper and still cost you more: you burn fuel getting there and back, and you lose ten minutes. So Gas On Route ranks every station near your route by what the stop really costs:

  • Cheapest is the fill-up plus the fuel burnt on the detour.
  • Best pick also puts a price on your time (12 €/h by default), so saving one euro isn’t worth a 15-minute loop.

The detour is the interesting part. A first estimate uses the distance from the station to the route line, but that can’t see a station on the other carriageway, a missing exit or a one-way street. So the 90 most promising candidates get their detour routed for real, in one OSRM table request: you → station → destination, minus the direct route. A station 300 m from the line that needs a 10 km loop drops down the list where it belongs.

Best pick and all the stops along the route

When there’s more than one sensible way to go, like Google Maps does, each alternative route gets its own stations and best price, so you can compare routes on fuel too.

Alternative routes compared on time and fuel price

Open when you get there

Opening hours turned out to matter more than I expected. The Ministry’s data has them as free text (L-V: 06:00-22:00; S-D: 24H, split shifts with y, single-digit hours, the odd stray space), so there’s a small parser for it. The app checks each station at the time you’d arrive, in the station’s own time zone (the Canary Islands are an hour behind), and a station that will be closed by then is never suggested. About 480 stations only list Monday, which is almost certainly truncated data, so those count as unknown rather than “closed six days a week”.

Electric cars too

The Ministry doesn’t publish charger prices, but the DGT (Spain’s traffic authority) publishes every public charging point: 12,000 sites as 85 MB of DATEX II XML a day. That’s far too big for a phone, so a small Python script on my server converts it every morning into a 630 KB gzipped JSON. Where Open Charge Map’s community knows the price, about three chargers in four, it’s merged in.

In electric mode the app filters chargers by your car’s plugs and minimum power, and ranks them by detour plus charging time, and price where known. Tell it your range and battery level and Best pick becomes a charger where you actually need one, not the one next to your front door.

Nearby, voice and the car

Not every stop needs a trip. Nearby shows the stations or chargers around you within a radius you choose, ranked the same way.

Nearby stations within a 10 km radius

You can pick a destination by search, by voice, or by long-pressing the map, and save favourites. When you’ve chosen a stop, Gas On Route hands off to your navigation app. That was its own small adventure: Google Maps drops your waypoints unless you also pass an origin, Organic Maps takes exactly two points in a strict order, and Waze only takes one. So the dialog says which apps route through the station to your destination and which only take you to the pump.

Hand-off to Google Maps, Waze or Organic Maps

There’s also an Android Auto app with favourites, search, voice search through the car’s microphone and Navigate, and the whole app is translated into English, Spanish, Catalan, Galician and Basque.

How it’s built

It’s Kotlin Multiplatform with Compose Multiplatform, one codebase for Android and iOS, in the same modular layout I used for Hyprr:

  • :domain holds the models, the corridor search and the ranking. It has no dependencies, so it’s easy to test.
  • :core:remote (Ktor) and :core:local (SQLDelight, for the price cache, favourites and settings) sit behind domain interfaces, so the features never touch them directly.
  • :feature:route, :feature:settings and :feature:welcome are the screens (Voyager and Koin); :feature:car is the Android Auto app.
  • The map is MapLibre Compose with OpenFreeMap tiles, so there are no API keys.

Finding the stations near a route sounds trivial until you multiply a detailed route line (thousands of points) by 11,400 stations. A grid index keeps it well under a frame’s worth of work.

The data has its quirks. The Ministry’s feed is 12 MB of JSON with a byte-order mark, decimal commas and keys with accents and spaces, and its server only offers TLS ciphers that iOS refuses by default. The app caches prices on the device for two hours and shows when they’re from.

Running my own servers

The public OSRM and Photon demo servers are fine for development, but not for an app in a store. So release builds use my own, on the same small droplet as this blog: OSRM for routing and Photon for place search, both for Spain. Serving them is light, but building OSRM’s data for Spain needs about 11 GB of RAM, more than the droplet has. So it’s built on my Mac and pushed. Photon and the charger list refresh themselves by cron.

nginx only answers requests carrying the app’s key, with per-IP rate limits. It keeps no access log, because the URLs contain people’s coordinates and searches. For monitoring, it writes an anonymous metrics line per request instead: endpoint, status, timing and size, nothing else. My ops dashboard turns those into charts and alerts. The app’s own usage statistics go to my self-hosted Umami, and they never include places, searches or locations.

Built with Claude Code

Like PublicPoolAndroid with Cursor, this one was built in close collaboration with an AI, this time Claude Code. I set the direction and made the product calls. It did a lot of the typing, the testing (the suite is past 350 tests on the JVM and the iOS simulator) and the checking on emulators and simulators. It also caught a fair share of things I wouldn’t have thought to check, like the Canary Islands’ time zone. The whole app, including two self-hosted services, translations and store assets, came together in a few days.

Try it

Gas On Route is open source under the MIT License, on my Git server. The Android version is in Google Play review now; I’ll update this post with the link once it’s live, and iOS will follow.