If you have booked a hotel for Umrah or Hajj, you have seen it: "200 m from the Haram". From where? To which gate? Measured how? The Grand Mosque in Makkah has dozens of named gates, and a distance that ends at the wrong one can add a long walk. For older and less mobile pilgrims that matters a lot.
So I built makkahmadina.net: a directory that links each hotel to a named mosque gate, gives a real walking distance, and says where the distance starts, how it was measured and when it was last checked.
Today it has 885 hotels (504 in Makkah, 381 in Madinah), 37 named gates, 32 ziyarat sites and 1,950 computed walking routes. This post is about the parts that turned out to be harder than they looked.
The stack
- Next.js 15 (App Router, TypeScript, Tailwind) for the site, in English and Turkish
- PostgreSQL 17 + PostGIS for places and distances
- Prisma for normal CRUD, plain parameterised SQL for the spatial queries
- OSRM (self-hosted) for walking routes
- MapLibre, lazy-loaded, so map JavaScript only loads when someone opens a map
- Docker Compose running the app, database and router on one server, behind Apache
One table for every place
Mosques, gates, hotels and ziyarat sites all live in one places table. location (and entrance, when it is known) are geography(Point, 4326) with a GiST index, so distance queries are fast and in metres.
Hotels come from OpenStreetMap, but I edit names, translations and details by hand. Two flags stop the next import from wiping that work:
-
lockedFromImporton a place: the importer leaves it alone. -
isEditorialon a translation: imports never overwrite it.
Source records are unique on (source, element_type, external_id), because an OSM node, way and relation can share the same numeric ID.
Step 1: candidate gates with PostGIS
The nearest gate in a straight line is often not the best gate to walk to. So the first step only picks candidates: the 5 nearest published gates in the same city.
SELECT g.id AS gate_id, ST_Distance(COALESCE(h.entrance, h.location), g.location) AS d FROM places h JOIN places g ON g.kind = 'GATE' AND g.city = h.city AND g.status = 'PUBLISHED' WHERE h.id = $1 ORDER BY d LIMIT 5; COALESCE(h.entrance, h.location) matters: if a hotel's entrance has been mapped, the distance starts there; otherwise it starts at the building centre, and the page says so.
Step 2: real walking routes with OSRM
Each candidate is then routed with OSRM's foot profile. The primary gate is the shortest usable walking route, not the closest point on a map.
"Usable" is the important word. OSRM always returns something, so every route goes through two sanity checks before it can be shown as the headline number:
- Snap distance. OSRM snaps the start and end points to the nearest path. If the hotel snaps more than 100 m away, or the gate more than 40 m, the route is probably starting from the wrong street. The snap legs are added to the distance and written into the route's notes, so a reviewer can see them.
- Detour. If the route is more than 2× the straight line and more than 400 m longer, it usually means a missing crossing or link in the map data (podiums, tunnels, fenced plazas), not a real detour.
A route that fails either check is not published as the headline. The hotel falls back to a clearly labelled straight-line distance, and the route is flagged needs review. Right now 117 of the 1,950 routed candidates are flagged, and they cluster in a few areas around both mosques, which points to gaps in the map data rather than random errors.
Fixing the map without editing OpenStreetMap
The area around the two mosques is hard for a router: huge open plazas mapped as areas (a router cannot walk across an area), gates with no path through them, and footpaths that stop a few metres short of each other.
Instead of uploading guesses to OpenStreetMap, a Python script (osmium + shapely) builds an extra OSM file that is merged into the routing graph only:
- Gate passages: each named gate gets a node linked to the nearest walkable way outside and inside, so a route can step through the gate instead of detouring to another entrance.
- Pavements: main roads near the mosques that people really walk along get a footway on the same nodes. Tunnels, bridges and roads tagged
sidewalk=noare excluded. - Dead ends: paths that stop just short of another path are joined.
- Plaza crossings: open squares get a 20 m walkable grid (with diagonals), joined to the paths around them.
Being honest about every number
Every route stores its method (STRAIGHT_LINE or ROUTED), its start point, and a verification level: UNVERIFIED, DESK_CHECKED or FIELD_CHECKED, with the date it was checked.
The pipeline only ever replaces unverified rows. Once a person has checked a route, a re-run cannot overwrite it, and if that checked route is the primary one, it stays primary.
This was the main design decision of the whole project: a confident wrong number is worse than an honest estimate. The page shows the method and the check status next to the distance, so readers can decide how much to trust it.
Keeping affiliate links apart
The site will earn from hotel booking links, but offers, price observations and outbound clicks live in their own tables, separate from editorial content. Only active offers are shown, click-outs go through a tracked /go/[offerId] route marked rel="sponsored", and the disclosure sits next to the button. A hotel's gate and distance never depend on whether it has an offer.
Running it
Everything runs from one docker compose file: the app, PostgreSQL with PostGIS, OSRM, and an ops profile for the data pipeline. One command re-runs migrations, seeds, the OSM import, hotel publishing and route computation. Refreshing the map data means downloading a new extract, rebuilding the OSRM graph and recomputing the routes.
What is still to do
- Mapping real hotel entrances, so more distances start at the door rather than the building centre.
- On-site checks of gates and routes, to move routes from desk-checked to field-checked.
- Reviewing the flagged routes and the areas where the map data is thin.
- Arabic and Urdu translations.
If you have walked these routes and something looks wrong, I would love to hear about it. And if you are building something with maps, routing or messy open data, I am happy to compare notes in the comments.
Map data © OpenStreetMap contributors, ODbL.
I'm Azeem, a freelance web developer. I build custom web apps, directories and data-heavy sites. You can see more of my work at jeemmo.com or email info@jeemmo.com.


