Geodesy icon indicating copy to clipboard operation
Geodesy copied to clipboard

Returned "Neighbors" incorrect for Precision of 4

Open G-Steve-E opened this issue 5 years ago • 4 comments

When I use Geodesy as shown below:

< let CurrentGeoHash = self.currentLocation.geohash(precision: 4) let CurrentNeighbors = self.currentLocation.neighbors(precision: 4) print("Geohash: ", CurrentGeoHash, " Geohash Neighbors: ", CurrentNeighbors) >

I get the following geohash for the current location and the array for the neighbors: Geohash: 9tbr
Geohash Neighbors: ["9w02", "9w02", "9tbr", "9tbq", "9tbq", "9tbq", "9tbr", "9w02"]

I believe the returned Geohash Neighbors for "9tbr" should be [N, NE, E, SE, S, SW, W, NW]: ["9w02", "9w08", 9tbx", 9tbw", 9tbq", 9tbn", 9tbp", 9w00"]

G-Steve-E avatar Dec 20 '19 19:12 G-Steve-E

i experience the same issue for precision 6. Seems to be a fundamental issue

nidegen avatar Dec 23 '19 16:12 nidegen

Well I guess it is not really supported for locations. Looking at the Unit Tests, it seems only to be supported for regions (which makes sense actually).

My workaround:

extension CLLocation {
  func getNeighboringBuckets(precision: Precision = .sixHundredTenMeters) -> [String] {
    let region = Region(hash: self.geohash(precision: precision))!
    return region.neighbors().map { $0.hash }
  }
}

nidegen avatar Dec 23 '19 17:12 nidegen

Based on documentation I would have expected the "neighbors" function to compute the geohash of the current location (i.e. current region) at the specified precision, then determine the neighbors of the that region, again at the specified precision.

G-Steve-E avatar Dec 23 '19 19:12 G-Steve-E

I have updated the Geodesy code in my app as Nicolas provided above and have verified that this does work for various precisions. Pod needs to be updated and also add the same for CLLocationCoordinate2D.

G-Steve-E avatar Dec 23 '19 22:12 G-Steve-E