Skip to the content.

1️⃣ What is Geohash?

Geohash is a system for encoding geographic coordinates (latitude and longitude) into a short string of letters and digits.

Use case: Efficient spatial indexing, location-based search, and proximity queries.


2️⃣ Why Geohash is Useful

  1. Compact representation of coordinates

    • Instead of storing two floats for latitude & longitude, you can store a string.
  2. Spatial indexing

    • Nearby coordinates often have similar Geohash prefixes, so you can do proximity search efficiently.
  3. Database optimization

    • Use Geohash as a key in databases (Redis, MongoDB, Postgres) to query regions fast.
  4. Hierarchical querying

    • Shorten a Geohash to get a larger area
    • Lengthen a Geohash to get a smaller, precise area

3️⃣ How Geohash Works

  1. Take latitude and longitude

    • Latitude range: [-90, 90]
    • Longitude range: [-180, 180]
  2. Divide the range into halves repeatedly

    • Assign 0 or 1 depending on whether the coordinate is in the lower or upper half
  3. Interleave bits of latitude and longitude

    • Create a single binary string
  4. Convert binary string to base32

    • Base32 characters: 0123456789bcdefghjkmnpqrstuvwxyz (note: letters like a, i, l, o are skipped for readability)

4️⃣ Example


5️⃣ How Geohash is Used

  1. Location-based search / services

    • Find all users within 1 km radius
    • Find all restaurants near a point
  2. Spatial databases

    • Store Geohash as an index column for faster queries
  3. Mapping & clustering

    • Aggregate points into cells for heatmaps

6️⃣ Benefits & Limitations

Feature Benefit / Limitation
Compact Encodes coordinates into short strings
Hierarchical Prefix length = spatial precision
Proximity Nearby points often share prefix
Limitations Rectangular area approximation (not perfect circle), edge cases near Geohash boundaries

7️⃣ Quick Analogy


If you want, I can also give a Java example showing how to encode/decode Geohash and do nearby searches — it’s very practical for system design and location-based apps.

Do you want me to do that?