Proximity Query Pattern and Neighbor Expansion
The Edge Problem
A point near a cell edge might be closer to points in adjacent cells than to points in its own cell. If you query only the center cell, you miss nearby points just across the boundary. A restaurant 100 meters away in a neighboring cell does not appear in results.
This is fundamental to all grid-based spatial indexing. The solution is neighbor expansion: query the target cell plus all 8 adjacent cells. This guarantees coverage of any circle that fits within the target cell.
Neighbor Expansion Algorithm
Given a geohash, compute its 8 neighbors: north, south, east, west, and the four diagonals. Each neighbor is a geohash of the same precision adjacent to the original. Query all 9 cells. Union the results. Post-filter by actual distance.
Computing neighbors requires understanding geohash structure. Moving east means incrementing longitude bits. Moving north means incrementing latitude bits. Libraries provide neighbor functions. For custom implementation, decode to lat/lon, offset by cell size, re-encode.
Query Radius vs Cell Size
If query radius exceeds cell size, expand to more neighbors. A 2 km radius query with 1 km cells needs the center plus at least the 8 immediate neighbors. For even larger radii, use coarser precision or expand to 25 cells (5x5 grid).
The trade-off is query count versus false positives. More cells mean more queries but fewer missed points. Fewer cells mean faster queries but potential gaps at edges. Post-filtering by exact distance catches any false positives from rectangular cells.