← Back to Blog

Loops that end where they start

22 Oct, 2026 15:52 SGT · 8 min read

  • Python
  • Maps

LoopWheeGo is a walking and cycling route planner for Singapore. You give it a start point and a distance, and it gives you loops that end where they start. You can try it at loopwheego.app.

Fitness mode: four cycling loops of about 5 km from East Coast Park, labelled Easier, Balanced and Tougher

Why I built it

I started cycling in Singapore in November 2025, when I found Anywheel. It's one of the cycling vendors in Singapore that provides cycles for a certain cost. It has a S$10 monthly subscription: the first 30 minutes of every ride are free, and after that it is S$0.50 for each extra 30 minutes.

I fell in love with cycling again. I used to cycle a lot during my bachelor's, but then COVID came and ended it, and I never got the opportunity to start again. With Anywheel and the cycling infrastructure in Singapore, I could, and it has been very good for my health.

After three or four months of riding, going to all kinds of places in Singapore even for small errands, I wanted something that would generate a loop route for me. My requirement was simple. If I want to ride 10 km today, I want a route that starts at the point I define and comes back to it.

Google Maps and Strava both offer something near it, and I was using Strava at the time. In Google Maps, the closest option is to search for a place, such as a hawker centre, and add a stop: point A is my house, point B is the hawker centre, and point C is my house again. That gives a loop, but an optimised one, because Google Maps always gives you the best route. Strava's route builder is a premium feature, and even there you have to draw the route yourself. You cannot get a generated one. I didn't want to put in that effort, and I didn't research other options in depth. What I wanted was to set a distance or a time and have the app work out the route.

How I built it

The first prototype took about six hours, using Gemini 3.1 Pro. It was my first project where I let AI write all of the code. The ideas and the architecture were mine, but I didn't want to do the coding, so I used Gemini to build it from my ideas.

I wanted to use open-source or free tools. For the map I started with Mapbox and later moved to MapLibre, with OpenStreetMap as the data. On top of the OpenStreetMap data there is OSRM, the Open Source Routing Machine, which does the route calculation.

At first I used the public OSRM server. It has rate limits, so I hosted my own on the free Arm server from Oracle Cloud (2 cores, 12 GB of RAM). OSRM is only mathematical computation, so that is more than enough. My backend now calls my own OSRM server, and the rate limits no longer matter.

Architecture: browser, Next.js frontend, FastAPI backend and the self-hosted services on the Oracle Cloud Arm server

Walking and cycling use separate OSRM containers, one with the foot profile and one with the bicycle profile. Each request names its profile. In Singapore some roads are walk-only, some are cycle-only and some allow both, so the two profiles matter.

How a loop is generated

OSRM routes between points. It has no loop feature, so I wrote the loop logic on top of it. Drawing a plain geometric shape around the start point, mostly triangles, gave routes that cut across parks and buildings. Those routes can never exist. So the generator picks candidate points and lets OSRM do the routing on real roads.

First it picks up to 16 anchor points around the start: curated places in Singapore at a suitable distance, plus eight compass directions on two rings. Then it pairs the anchors, keeping pairs at least 35° apart and the best 40 pairs. Each pair goes to OSRM as a round trip from the start through both anchors and back, and OSRM picks the order. Loops that are too short, too long or physically implausible are thrown out, and the rest are scored.

How a loop is generated: anchor points, anchor pairs, OSRM round trip, filter, score

Here is an example for a 10 km loop. The compass points sit roughly 2 km and 3.6 km out from the start, on the two rings. A loop is accepted if it is between 7 km and 13.5 km, because there is very little chance of getting exactly 10 km. A loop that retraces its own roads gets a penalty (an out-and-back counts as half overlapped), and a route is thrown out if any single stretch of it is longer than a walker or a cyclist would plausibly cover in one hop. The scoring and geometry helpers have 20 unit tests, and they run without any Docker services.

Fitness mode

Fitness mode is where you set a distance. It does not just return the best loops from one search. It runs the generator at up to nine target distances around the one you asked for. Searches close to your distance ask for more variants: three at exactly your distance, two within 12% of it, and one otherwise. The loops are merged, near-duplicates are dropped, and then I look up the climb along each loop. Each loop gets an effort score: its distance plus a penalty for climbing, where 10 m of climb counts as 100 m of flat when walking and 60 m when cycling.

How Fitness mode keeps loops

Choosing which loops to keep is a series of checks. Each loop gets a score where lower is better: 2.4 times how far its distance is from your request, plus 0.9 times how far its effort is from it, plus a small extra penalty if it is longer than you asked for. I take the best eight and keep only those within 12% of your distance (never less than 750 m of slack). If none of them pass, I fall back to the best three. Then comes a diversity check. If more than 82% of a loop's points are shared with a loop I have already kept, I skip it and hold it as a backup, which I only use if I would otherwise end up with fewer than four.

How Fitness mode labels loops

The labels are relative. I sort the kept loops by effort, and the lowest third are Easier, the highest third are Tougher, and the rest are Balanced. With four loops that means one Easier, two Balanced and one Tougher, as in the screenshot at the top of the post. If only one loop is left, it is just Balanced. So "Tougher" means tougher than the other loops in that set, not hard in any absolute sense.

Explorer mode

Sometimes I cycle to explore, not for fitness. Explorer mode lets you set a distance or a time (a time is converted to a distance using fixed speeds of 4.5 km/h for walking and 10 km/h for cycling) and pick categories of places: parks, nature, waterfront, monuments, heritage, museums, viewpoints, hawker centres, cafes and arts.

At first this didn't work. The way the AI was writing the logic was breaking it, and I was not getting proper routes. Then I gave it an idea of how to tackle it: stop building the route around the places. We don't pick from predefined routes. We generate the loops from what the person asks for, with the same loop generator as Fitness mode, and only then look at which places each loop passes.

How Explorer mode finds and ranks places

Once the routes exist, the question is which one is the most interesting. For a loop, I ask for places in your categories within 600 m of the route. For an A-to-B route the corridor is 350 m, because there I want places you actually pass. I keep at most eight places per route. A route's score is the number of places plus half a point for each distinct category, so four places across three categories (5.5) beat four places of one category (4.5). That half point is there to give you variety instead of eight cafes. If two routes tie, the shorter one comes first.

A place does not have to be on the route. Some places are inside areas that roads don't reach, and being within 600 metres is good enough, because you can get off the bike and walk to it. You can also add a place as a stop and the route is regenerated through it.

Explorer mode: a 5 km cycling loop from East Coast Park with 8 places of interest along it

Keeping the Fitness and Explorer modes separate, and fixing the places problem, are the two things in this project that I'm proudest of.

What it can't do

LoopWheeGo exports a route as a GPX file, but people then have to take that file into another app to follow the route, because I can't add navigation to a website. To do that I would have to turn it into a mobile web app, where navigation is a lot more difficult. That limitation is why I never released it properly. It also only covers Singapore, by design. The map data, the bounds check and the list of places are all Singapore-specific.

It stayed a hobby project. I built it in April 2026 and never promoted it. If you want to try it, it's at loopwheego.app.


I dictated this post with Wispr Flow. Claude cleaned up the text and checked the technical details against the code, and I reviewed it before publishing.