neighbors method

Map<String, String> neighbors(
  1. String geohash
)

Returns a Map<String, String> containing the Direction as the key and the value being the geohash of the neighboring geohash in that direction.

Implementation

Map<String, String> neighbors(String geohash) {
  if (geohash.isEmpty) {
    throw ArgumentError.value(geohash, "geohash");
  } else if (!geohash
      .contains(new RegExp(r'^[0123456789bcdefghjkmnpqrstuvwxyz]+$'))) {
    throw ArgumentError("Invalid character in GeoHash");
  }

  return {
    Direction.NORTH.toString().split(".")[1]:
        _adjacent(geohash: geohash, direction: "n"),
    Direction.NORTHEAST.toString().split(".")[1]: _adjacent(
        geohash: _adjacent(geohash: geohash, direction: 'n'), direction: 'e'),
    Direction.EAST.toString().split(".")[1]:
        _adjacent(geohash: geohash, direction: 'e'),
    Direction.SOUTHEAST.toString().split(".")[1]: _adjacent(
        geohash: _adjacent(geohash: geohash, direction: 's'), direction: 'e'),
    Direction.SOUTH.toString().split(".")[1]:
        _adjacent(geohash: geohash, direction: 's'),
    Direction.SOUTHWEST.toString().split(".")[1]: _adjacent(
        geohash: _adjacent(geohash: geohash, direction: 's'), direction: 'w'),
    Direction.WEST.toString().split(".")[1]:
        _adjacent(geohash: geohash, direction: 'w'),
    Direction.NORTHWEST.toString().split(".")[1]: _adjacent(
        geohash: _adjacent(geohash: geohash, direction: 'n'), direction: 'w'),
    Direction.CENTRAL.toString().split(".")[1]: geohash
  };
}