In our project, we are trying to store the location of each farm in a database, and when a worker searches for farms in a certain location, we need to query the table and return farms near that area.
While trying to find out how to do this, we found the concept of ‘Geohashing’. This essentially splits the earth into a bunch of labelled squares. Each of these squares are split into smaller and smaller squares, adding an extra character to the hash code during each layer.
All the squares in the g block start with g. If you were to zoom in on g5, it would also be split into squares, 3 characters long, that all start with g5. Let’s say one of these 3 character squares is g5p, for example. g5p would be split into squares 4 characters long that all start with g5p, and so on. The longer the string, the more precise the location.
So for our project, we can pinpoint the location of the farm with a longer geohash (say 8 characters long) and store that value in the table. A user looking for work could search using a vague location term like a zip code, and we would convert that into a geohash that’s 5 characters long . We could then query the table for any farms who have a geohash whose first 5 characters match the user search geohash.
I thought this was a pretty cool way to search for specific locations in a certain area!