latlon-geohash icon indicating copy to clipboard operation
latlon-geohash copied to clipboard

Bounding box search?

Open JoseExposito opened this issue 4 years ago • 1 comments

Hi,

First, thank you very much for the library :)

I'm storing items in my DB associated to a geohash with precision 6 and I need to get all items inside a rectangular area in the map.

Is there any API to get all the geohashes inside a rectangle defined by 2 (or 4) coordinates? I am not sure if I can use neighbours to archive this.

Thank you very much in advance.

JoseExposito avatar Jul 29 '19 08:07 JoseExposito

geohashes are infinite precision so the result of such an operation would always be an infinite set unless you specify the precision in the query. There's probably more efficient ways to do it but the first thing that comes to mind is you'd use a loop to generate "lines" incremented at the desired precision along a straight trajectory from one corner to the next, then you could then construct a loop which increments the geohash by one and checks if the current position is in the "lines" array. Essentially you're doing a raster scan like an old TV. If it's not in the lines array, add it to an "inside" array, if it is, jump to one increment south of the start position of that line, if that's also a line, you've hit the end.

Something like that.

WhiskeyTuesday avatar Feb 07 '20 19:02 WhiskeyTuesday