Geohash encoding
A geohash turns a pair of coordinates into a compact, sortable string. It is widely used in databases and search engines because points that are near each other usually share a long common prefix, letting you find neighbours with a simple range scan.
How it works
The algorithm interleaves bits of longitude and latitude. Starting from the full ranges of -180 to 180 for longitude and -90 to 90 for latitude, it repeatedly halves a range and records a 1 if the coordinate falls in the upper half or a 0 otherwise. Bits alternate between longitude (first) and latitude. Every five bits become one base-32 character.
lat 57.64911, lng 10.40744 -> u4pruydqqvj
The more characters you request, the more halving steps run, and the smaller the resulting cell.
Example and tips
Encoding a city-center coordinate at precision 6 gives a cell roughly a kilometre wide, which is handy for clustering. For pinpoint accuracy choose precision 9 or higher. Remember the boundary edge case: two physically close points may not share a prefix if they sit on opposite sides of a cell edge, so for robust neighbour search you should also check adjacent cells.