Guides

What is Geohashing?

Developer Relations Team on Apr 11, 2024
What is Geohashing?

Geohashing (or geohash) is a geocoding method used to encode geographic coordinates (latitude and longitude) into a short string of digits and letters delineating an area on a map, which is called a cell, with varying resolutions (sizes). The more characters in the string, the more precise the location (smaller cell).

What is an example of a geohash?

Geohash is a public domain of encoding coordinates. An example of a geohash is the coordinate pair 28.6132,77.2291 being converted into a geohash of ttnfv2u. 

What is the maximum length of a geohash?

The maximum length of a geohash is 12 characters. The length of a Geohash string depends on the desired level of precision or granularity required for representing a geographic location.

Geohash length sizes and corresponding precision levels examples:

  • A Geohash of length 1 represents a large area, such as a continent.

  • A Geohash of length 2 represents a smaller area, such as a country.

  • A Geohash of length 3 represents a region or large city.

  • A Geohash of length 4 represents a smaller city or town.

  • Geohashes of length 5 or higher represent progressively smaller areas, down to street level and even specific locations.

For example, a Geohash of length 6 might represent a neighborhood or a specific landmark, while a Geohash of length 12 could represent a location accurate to within a few meters.

How Does Geohashing Work?

Geohash algorithm and calculation

Geohashes use Base-32 alphabet encoding (characters can be 0 to 9 and A to Z, excl "A", "I", "L" and "O”). Imagine the world is divided into a grid with 32 cells. The first character in a geohash identifies the initial location as one of the 32 cells. This cell will also contain 32 cells, and each one of these will contain 32 cells (and so on repeatedly). Adding characters to the geohash sub-divides a cell, effectively zooming in to a more detailed area.

Precision factor determines the size of the cell. A precision factor of one (geohash 1) creates a cell 5,000km high and 5,000km wide. Precision factor of six creates a cell 0.61km high and 1.22km wide, and a precision factor of nine creates a cell 4.77m high and 4.77m wide (cells are not always square).

Geohashing Examples and Use Cases

Geohashing was originally developed as a URL-shortening service but it is now commonly used for spatial indexing (or spatial binning), location searching, mashups and creating unique place identifiers.

Geohash benefits

A geohash is shorter than a regular address, or latitude and longitude coordinates, and therefore easier to share, remember and store.

  • Social Networking: Chat with people near you within a particular cell, and to create chat apps.

  • Proximity Searches: Find nearby locations using API mapping or geolocation APIs and identify places of interest, restaurants, shops and accommodation establishments in an area.

  • Digital Travels: Geohashers go on global expeditions to meet people and explore new places. The twist: the destination is a computer-generated geohash and participants in this turnkey travel experience have to write up and post their story on the internet.

  • Custom Interactive Apps: Geohashing can be used to create real-time interactive apps.

You can try it out here. Use the coordinates 40.748440989 and -73.985663981 for a view of the area around the Empire State Building in New York. Change the precision factor to increase or decrease the resolution (size of the cell), or use the geohash dr5ru6j2c5fqt for a 13-digit precision factor to zoom right in.

What are the drawbacks to using a geohash?

Disadvantages to geohashing include:

  1. Using a grid based geohashing algorithm does need meet high-precision requirements

  2. Geohashing deviation changes as latitude increases because the Earth is an irregular ellipse.

Ready to incorporate real-time functionality in your app? Create a free PubNub account today.

Geohash alternatives

There are several options for representing geographic coordinates and handling spatial data. Some of most popular solutions include:

  1. Quadtree: A quadtree is a hierarchical data structure used for spatial partitioning of two-dimensional space. It recursively subdivides space into quadrants, allowing efficient storage and retrieval of spatial data. Quadtree is commonly used in geographic information systems (GIS) and computer graphics.

  2. S2 Geometry: S2 geometry is a spherical geometry library developed by Google for representing and manipulating geographic shapes on the Earth's surface. It divides the Earth into regions of varying sizes using a hierarchical grid system similar to Geohash but with some differences in encoding and precision.

  3. H3: H3 is a hierarchical hexagonal grid system developed by Uber for spatial indexing and analysis. It divides the Earth into hexagonal cells of varying sizes, providing a uniform and efficient way to represent geographic areas at different resolutions.

  4. R-tree: An R-tree is a spatial index structure used for indexing multidimensional information, particularly in databases and GIS. It organizes spatial objects into a tree hierarchy, allowing efficient queries for nearest neighbors, range searches, and spatial joins.

  5. GeoJSON: GeoJSON is a format for encoding geographic data structures using JavaScript Object Notation (JSON). It provides a lightweight and human-readable way to represent points, lines, polygons, and other geometric shapes, making it suitable for storing and exchanging spatial data in web applications and geographic databases.

Other Resources