Geohash

Updated June 3, 2026
M
Magic Magnets Team
5 min read

Have you ever wondered how apps like Uber or Tinder know exactly who is around you in milliseconds? If they had to calculate the exact distance between you and every other user on earth using complex math, your phone would probably melt.

Instead, they use a clever trick called a Geohash.

The World is a Waffle

Think of the Earth as a giant waffle. A Geohash takes the entire globe and divides it into a grid. Each square in that grid gets a unique letter or number.

But it doesn't stop there. If you zoom in on one of those squares, you'll see it's actually made of smaller squares, and each of those smaller squares has its own unique letter or number added to the end of the first one.

This process keeps going. The more letters you add to your Geohash, the smaller the square gets, and the more precise your location becomes.

For example:

  • 9 might cover half of North America.
  • 9q narrows it down to the West Coast.
  • 9q8 gets you into California.
  • 9q8yy gets you into San Francisco.
  • 9q8yyk8 pinpoints a specific coffee shop in SF.
Quiz Time

What does a longer Geohash string represent?

Why is this so powerful?

In a database, searching for points within a radius using raw latitude and longitude is computationally expensive. You have to use the Haversine formula on every row.

With Geohashes, finding nearby points becomes a simple prefix string match.

If your Geohash is 9q8yy, and you want to find drivers near you, you just ask the database: "Give me all drivers whose location starts with 9q8yy."

Databases (like Redis, MongoDB, or PostgreSQL) are incredibly fast at matching string prefixes using indexes. This turns a complex math problem into a lightning-fast text search.

Quiz Time

Why are Geohashes faster for proximity searches than raw latitude/longitude?

The Edge Case (Literally)

There's one catch: two places can be right next to each other but sit on opposite sides of a grid boundary, meaning their Geohashes will look completely different.

Imagine you are standing on the border of a square. Your Geohash might be 9q8yy, but a car 10 feet away across the border might be in 9q8yz. A simple prefix search for 9q8yy would miss that car entirely!

To solve this, real-world systems don't just query your exact Geohash square. They query your square plus the 8 surrounding squares. This ensures you catch everything nearby, even across boundaries.

Quiz Time

Two locations right next to each other can have completely different Geohashes.

Quiz Time

How do real-world systems handle the Geohash boundary edge case?

Real-World Examples

  • Uber and Lyft: Use Geohashes to quickly group drivers and riders in the same area.
  • Tinder: Uses similar grid-based systems to find potential matches within your specified radius.
  • Yelp: Uses them to find restaurants near your current location without scanning the entire country.
Quiz Time

A Geohash prefix search on `9q8yy` will always find all drivers within a fixed radius of that cell.

Summary

Geohashes turn 2D coordinates (latitude and longitude) into 1D strings. They divide the world into a hierarchical grid, where longer strings mean more precise locations. By converting proximity into string prefix matching, they allow databases to find nearby points with incredible speed, making location-based apps possible at a massive scale.

Quad Trees

How helpful was this content?

Comments

0/2000

Sign in to join the discussion

Saved on this device only

Sign in to sync progress across devices