Geohashing: Encoding the location coordinates
In 2008, Gustavo Niemeyer invented a geocoding method where geographic coordinates (latitude and longitude) were encoded in short alphanumeric strings. The basic idea was first brought on by G.M. Morton in 1996. For a better understanding, let’s see an example,
The latitude and longitude of Kathmandu, Nepal are 27.717245 and 85.323959 respectively and we write the coordinates like (27.717245, 85.323959).
Now, if we represent them in geohash, it becomes short and easy to remember,
You can easily see geohashing used in some of the databases like MySQL, Redis, Amazon DynamoDB, and Google Cloud Firestore.
How does Geohashing work?
Geohashing works as a hierarchical spatial index that uses a Base-32 alphabet encoding system. There are 32 cells, and each cell further contains 32 individual cells. The first character in the encoded geohash identifies an initial location that can be understood by thinking of the place as a point. The world is divided into smaller and smaller cells repeatedly until the location is precise. The size of the cell also determines the precision of the location. The points or the location are closer if the prefix matches. The longer the match of the prefix, the closer the location.
Tuutttg08kfg are very close since they share the same prefix
In addition, the larger the characters in the string (maximum 12), the more precise the location. This means that we also have anonymity with the use of geohash since only the area is represented in the encoded alphanumeric string.
Cell Sizes for Geohashing
Let’s see some of the use cases of geo hashing.
- Storing and representing a location in a database is easy and simple.
- Sharing and remembering is easy since it is less complicated than latitude and longitude. It can be represented as a URL.
- We can find out nearby points with string comparison which is very efficient in case we have large indexes.
I hope this article was helpful to you.
Please don’t forget to applaud this article and follow me!!!
Any kind of feedback or comment is welcome!!!
You can also subscribe to my stories via email so that you’ll get notified whenever I bring out an article on a new subject.
Thank you for your time and support!!!!
Keep Reading!! Keep Learning!!!