neighbours method

Map<Direction, int> neighbours(
  1. int geohash
)
inherited

Returns all eight neighbours for the given geohash string. It does call adjacent eight times, so when you don't need every value, maybe you are better using that function. Although it's a little bit more efficient by not calculating an adjacent code twice for diagonal directions.

When near the northern or southern world boundary, this function can return just five values.

Implementation

Map<Direction, T> neighbours(T geohash) {
  T? north;
  try {
    north = adjacent(geohash, Direction.north);
  } on OutOfWorldBoundsException {
    // keep null
  }

  T? south;
  try {
    south = adjacent(geohash, Direction.south);
  } on OutOfWorldBoundsException {
    // keep null
  }

  return {
    if (north != null) Direction.northWest: adjacent(north, Direction.west),
    if (north != null) Direction.north: north,
    if (north != null) Direction.northEast: adjacent(north, Direction.east),
    Direction.west: adjacent(geohash, Direction.west),
    Direction.east: adjacent(geohash, Direction.east),
    if (south != null) Direction.southWest: adjacent(south, Direction.west),
    if (south != null) Direction.south: south,
    if (south != null) Direction.southEast: adjacent(south, Direction.east),
  };
}