"Find everything within 3km" sounds simple. Databases hate it.
Latitude and longitude are two independent numbers. There's no single ordering of points on a sphere, so a normal index can't help. You end up scanning.
The trick: stop storing coordinates, start storing cells.
Cut the world into a grid. Cut each square into smaller squares. Keep going. Every point on Earth now has a short string — and nearby places share a prefix.
| Prefix | Resolves to |
|---|---|
9q8yy | A neighbourhood |
9q8yyk | A few streets |
9q8yyk8 | A block |
"Nearby" just became "starts with the same letters." A B-tree does that instantly.
The catch: cells have edges. A driver 50 metres away across a boundary looks far apart in text. So you always search the neighbours too.
