Geohash Encoder Decoder - Grid Cell System
Free Geohash tool: encode/decode geohash codes, view grid cells, find neighbors. Convert coordinates to geohash for proximity search and spatial indexing.
What is Geohash?
Geohash is a geocoding system that encodes geographic coordinates (latitude/longitude) into a short alphanumeric string. Developed by Gustavo Niemeyer in 2008, it divides the world into a hierarchical grid where each character adds precision to the location.
A geohash like 'w7p9v0rr' represents a specific rectangular area on Earth. The longer the geohash, the smaller and more precise the area. This makes geohash perfect for proximity searches, spatial indexing, and location-based queries in databases.
Key features of Geohash:
- Hierarchical structure: Longer strings represent smaller areas within larger ones
- Proximity property: Similar geohashes are geographically close (with some exceptions)
- Easy to use: Simple string comparison for rough proximity checks
- Database friendly: Can be indexed as strings for fast spatial queries
- URL safe: Uses base-32 characters (0-9, a-z excluding a, i, l, o)
Geohash is widely used in location-based services, NoSQL databases (MongoDB, Redis), and mapping applications for efficient spatial data management.
How Geohash Works
Geohash uses a base-32 encoding system that progressively divides the Earth into smaller rectangular cells. Each character in the geohash string represents one step in this hierarchical subdivision:
Precision levels and cell sizes:
- 1 character: ~5,000km × 5,000km (continental level)
- 3 characters: ~156km × 156km (city level)
- 5 characters: ~5km × 5km (neighborhood)
- 7 characters: ~150m × 150m (street level)
- 9 characters: ~5m × 5m (building level)
- 12 characters: ~4cm × 2cm (sub-meter precision)
Encoding process:
The algorithm alternates between longitude and latitude bits, dividing the coordinate space in half with each bit. Every 5 bits are encoded as a single base-32 character, building the geohash string from left to right.
Neighbor finding:
Geohash provides efficient neighbor lookup by calculating adjacent grid cells. This is useful for 'find nearby locations' queries, though boundary cases require special handling.
Use Cases for Geohash
Geohash is essential in various location-based applications:
- Proximity Search: Find nearby points of interest within a geohash prefix
- Spatial Indexing: Organize location data in databases for fast queries
- Clustering: Group nearby locations by truncating geohash precision
- Caching: Use geohash as cache keys for location-based data
- URL Shortening: Share approximate locations in short URLs
- Database Sharding: Distribute location data across servers by geohash prefix
Geohash vs Other Systems
Comparing Geohash with other geocoding systems:
- Geohash vs Lat/Lon: More compact, easier to search by prefix, but less precise
- Geohash vs QuadKeys: Similar concept, but different encoding (base-32 vs base-4)
- Geohash vs Plus Codes: Geohash uses variable precision, Plus Codes have fixed format
- Geohash vs H3: H3 uses hexagons (better shape), geohash uses rectangles (simpler)
Choose geohash for database indexing and prefix-based proximity searches. Use other systems when you need human-readable codes (Plus Codes) or better spatial properties (H3).
Working with Neighbors
Geohash provides 8 neighboring cells (N, NE, E, SE, S, SW, W, NW) for each location. This is useful for expanding search areas:
- Simple proximity: Query the main geohash and its 8 neighbors (9 cells total)
- Edge cases: Locations near cell boundaries may require neighbor checks
- Radius search: Use multiple precision levels and neighbors for circular areas
- Real-time updates: Monitor geohash changes as objects move between cells
Note that geohash neighbors don't perfectly handle all edge cases (especially at longitude boundaries), so distance calculations may still be needed for precise proximity queries.