List of geohashes by area
I need an approach to get all geohashes with a specific length that cover a given MKMapRect (or a given north-west and south-east coordinate) to fetch geo-data within a specific area and cache the fetched data for future use. E.g.
+ (NSArray *)hashesForNorthLatitude:(double)northLat
eastLongitude:(double)eastLon
southLatitude:(double)southLat
westLongitude:(double)westLon
length:(unsigned int)length;
related http://stackoverflow.com/questions/36705355/finding-geohashes-of-certain-length-within-radius-from-a-point
Step 4: Calculate the GeoHash of all four corners of MBR
Ex: for a point in NYC, say (40.75798, -73.991516), distance: 800 Meters and GeoHash length: 12
NorthWest : dr5ruj4477kd SouthWest : dr5ru46ne2ux SouthEast : dr5ru6ryw0cp NorthEast : dr5rumpfq534 Step 5: From these GeoHashes, calculate the Query Bounding Box(MBR) Prefix: dr5ru
This would give you the coarser GeoHash which completely contains our MBR and hence the query region. In other words, all points indexed by dr5ru, yielding with 32 GeoHashes from dr5ru0 - dr5ruz
Final Step:
To find the exact grids (or) GeoHashes that correspond to our Query Circle(Square(MBR) to be precise), we should pick from these 32 GeoHashes by representing a recurring (4X8) Matrix using 2D Array.
In our example: we get dr5ru + J, M, H, K, 5, 7, 4, 6. All these GeoHashes represent the points that are within 800 meters from the Central Query Point, Except very few GeoHashes, which could not be avoided, because of considering MBR instead of a perfect circle.
https://gist.github.com/johndpope/180e63f45f90dc5824e800e4324c8343