Geohash is a latitude/longitude geocode system invented by Gustavo Niemeyer when writing the web service at geohash.org, and put into the public domain. It is a hierarchical spatial data structure which subdivides space into buckets of grid shape.
Geohashes offer properties like arbitrary precision and the possibility of gradually removing characters from the end of the code to reduce its size (and gradually lose precision).
As a consequence of the gradual precision degradation, nearby places will often (but not always) present similar prefixes. Conversely, the longer a shared prefix is, the closer the two places are.
The purpose of the geohash.org service, launched in February 2008, is to offer short URLs which uniquely identify positions on the Earth, so that referencing them in emails, forums, and websites is more convenient.
To obtain the Geohash, the user provides an address to be geocoded, or latitude and longitude coordinates, in a single input box (most commonly used formats for latitude and longitude pairs are accepted), and performs the request.
Besides showing the latitude and longitude corresponding to the given Geohash, users who navigate to a Geohash at geohash.org are also presented with an embedded map, and may download a GPX file, or transfer the waypoint directly to certain GPS receivers. Links are also provided to external sites that may provide further details around the specified location.
The main usages of Geohashes are
- as a unique identifier.
- represent point data e.g. in databases.
Geohashes have also been proposed to be used for geotagging.
When used in a database, the structure of geohashed data has two advantages. First, data indexed by geohash will have all points for a given rectangular area in contiguous slices (the number of slices depends on the precision required and the presence of geohash "fault lines"). This is especially useful in database systems where queries on a single index are much easier or faster than multiple-index queries. Second, this index structure can be used for a quick-and-dirty proximity search - the closest points are often among the closest geohashes.
Using the hash ezs42 as an example, here is how it is decoded into a decimal latitude and longitude
Decode from base 32 
The first step is decoding it from base 32 using the following character map:
This operation results in the bits 01101 11111 11000 00100 00010. Assuming that counting starts at 0 in the left side, the even bits are taken for the longitude code (0111110000000), while the odd bits are taken for the latitude code (101111001001).
Decode binary to decimal 
Each binary code is then used in a series of divisions, considering one bit at a time, again from the left to the right side. For the latitude value, the interval -90 to +90 is divided by 2, producing two intervals: -90 to 0, and 0 to +90. Since the first bit is 1, the higher interval is chosen, and becomes the current interval. The procedure is repeated for all bits in the code. Finally, the latitude value is the center of the resulting interval. Longitudes are processed in an equivalent way, keeping in mind that the initial interval is -180 to +180.
Finishing the procedure should yield approximately latitude 42.6 and longitude -5.6.
Worked example 
Here's a worked example decoding 101111001001 into 42.6. To start with, we know the latitude is somewhere in the range -90 to 90. With no bits, we'd have to guess the latitude was 0, giving us an error of ±90. With one bit, we can decide whether its in the range -90 to 0, or 0 to 90. The first bit is high, so we know our latitude is somewhere between 0 and 90. Without any more bits, we'd guess the latitude was 45, giving us an error of ±45
Each subsequent bit halves this error. This table shows the effect of each bit. At each stage, the relevant half of the range is highlighted in green - a low bit selects the lower range, a high bit the upper range.
The last column shows the latitude, simply the mean value of the range. Each subsequent bit makes this value more precise.
(The numbers in the above table have been rounded to 3 decimal places for clarity)
Final rounding should be done carefully in a way that
So if rounding 42.605 to 42.61 or 42.6 is correct, rounding to 43 it is not.
|geohash length||lat bits||lng bits||lat error||lng error||km error|
|2||5||5||± 2.8||± 5.6||±630|
|3||7||8||± 0.70||± 0.7||±78|
|4||10||10||± 0.087||± 0.18||±20|
|5||12||13||± 0.022||± 0.022||±2.4|
|6||15||15||± 0.0027||± 0.0055||±0.61|
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 Equator or a meridian can result in Geohash codes with no common prefix.
Secondly a geohash essentially defines a bounding box within which a location lies, therefore two locations may be spatially very close but have different geohashes. In order to be useful to proximity searches, the surrounding eight geohashes of a geohash must be calculated and the locations matching these pulled out, therefore complicating potential usage in proximity searches.
Despite those issues, there are possible workarounds, and the algorithm has been successfully used in MongoDB and HBase to implement proximity searches.
License and patents 
See also 
- Grid (spatial index)
- Morton number (number theory)
- Natural Area Code
- Maidenhead Locator System
- Military grid reference system
- Visualizing Geohash
- Perl module to interact with geohash.org
- Java classes for encoding and decoding Geohashes without interacting with geohash.org
-  Java library for encoding and decoding Geohashes without interacting with geohash.org and find the adjacent
- Another implementation of Geohash in Java containing quite some more features
- MySQL Function for encoding and decoding geohash
- PostGIS function that returns a geohash representation of a geometry
- Ruby gem for encoding and decoding geohashes without interacting with geohash.org
- Perl module for encoding and decoding geohashes without interacting with geohash.org
- PHP class for encoding and decoding geohashes without interacting with geohash.org
- Python module for encoding and decoding geohashes without interacting with geohash.org
- Haskell library for encoding and decoding geohashes without interacting with geohash.org
- C library for encoding and decoding geohashes without interacting with geohash.org
- Go package for encoding / decoding geohashes to UTM or lat / long
- Objective-C library for encoding and decoding geohashes without interacting with geohash.org
- Ocaml module for encoding and decoding geohashes without interacting with geohash.org
- Proposal for a similar encoding and associated 'geo' URL scheme
- http://loc.is - a geohash designed for analytics.
- kml file for Google Earth displaying geohash grid
- ngeohash, nodejs module for encoding and decoding geohash
- geoplace.it: a free service to reference positions using an approach different than geohash.org and with a more accurate service
- A geohash implementation in pure ruby (~50 sloc)
- Area Check Tool
- Michael S. on geospatialsemanticweb.com, June 8, 2008
- Geospatial Indexing in MongoDB
- Spatial Keys
- geohash.org announcement post in groundspeak.com forum
- Compact text encoding of latitude/longitude coordinates - Patent 20050023524
- Does Microsoft Infringe the Natural Area Coding System?
- The Natural Area Coding System - Legal and Licensing