Geohashing

What is Geohashing?

Geohashing is a very nifty algorithm for expressing geographic coordinates (lat,lon) as a short string that was invented by Gustavo Niemeyer. It exhibits some useful properties like arbitrary precision and the possibility of gradually removing characters from the end of the hash to reduce its size (and gradually lose precision). Furthermore, nearby places will often (but not always) present similar prefixes while the longer a shared prefix is, the closer the two places are.

It is a hierarchical spatial data structure which subdivides space into buckets of grid shape, which is one of the many applications of what is known as a Z-order curve, and generally space-filling curves. - Article on Wikipedia

For example, the geohash of Southampton is: gcp185c6kpxc
and that of neighbouring Portsmouth is: gcp1p6ght

Due to their proximity, they share the first characters of the hash gcp1.

Limitations

One limitation of the Geohash algorithm is in attempting to utilize it to find points in proximity to each other based on a common prefix. Edge case locations close to each other but on opposite sides of the 180 degree meridian will result in Geohash codes with no common prefix (different longitudes for near physical locations). Points close by at the North and South poles will have very different geohashes (different longitudes for near physical locations).

Two close locations on either side of the Equator (or Greenwich meridian) will not have a long common prefix since they belong to different 'halves' of the world. Put simply, one location's binary latitude (or longitude) will be 011111... and the other 100000...., so they will not have a common prefix and most bits will be flipped. This can also be seen as a consequence of relying on the Z-order curve (which could more appropriately be called an N-order visit in this case) for ordering the points, as two points close-by might be visited at very different times. However, two points with a long common prefix will be close-by.

Article on Wikipedia

Using Geohashes

A comprehensive list of geohashing implemenations are available here.