4

Given that I know the lat/lng of a person's location, I can find the geohash of where they are. But I want to also find all the geohashes that within their "view".

So if I know the lat/lng and radius, let's say from a google map view, I want to know all of the geohashes that included within that space. I know that I would have to choose a number of units. Let's say 5 units, which I believe is ~3803m per geohash.

Is there an easy way to do this? I could come up with a crude algorithm, but I don't know enough about geohashing to complete each step.

Let's say we're at Buckingham Palace (51.501364, -0.141890), and our "view" has a radius of 1km.

In theory I could do this. Assuming I have a library that can turn lat/lng into a geohash, and vice versa.

  1. Given that we know the center of the map, find the corners (1km NW, 1km NE, 1km SW, 1km SE).
  2. I could then calculate the geohash of top left corner. ADD ~3803m East, calc the geohash. Repeat until the geohash is equal to the geohash of the top right corner.
  3. I could then go down the right side doing the same thing until I reached the bottom left corner. Do the same on the right side. Then fill in the middle, going from the square one below the top left corner, go across until I reach the right side. Back to the left but one block down, and go across again. Back until I finally reach the known bottom right corner.

This may work, I think it would be slow, and not entirely accurate. I'm sure there's an easier way to do this. Does anyone know of a formula or algorithm that could solve this?

Given a lat/lng and radius(R), find all the geohash squares (of an N length), that cover the square who's edges are R meters from the center (lat/lng).

Thanks! Any partial answers or help/formulas working with geohashing would be greatly appreciated!

RoyalTS
  • 9,545
  • 12
  • 60
  • 101
Peter R
  • 3,185
  • 23
  • 43
  • I guess, the question is answered here: https://stackoverflow.com/questions/36705355/finding-geohashes-of-certain-length-within-radius-from-a-point – Ufos Jan 16 '18 at 17:13

0 Answers0