toSubBounds static method

List<GMULatLngBounds> toSubBounds(
  1. GMULatLngBounds bounds, {
  2. int division = 2,
})

Splits Bound to smaller bounds equivalent of number of division^2

Implementation

static List<GMULatLngBounds> toSubBounds(
  GMULatLngBounds bounds, {
  int division = 2,
}) {
  List<GMULatLngBounds> subBounds = [];

  final northEast = bounds.northEast;
  final southWest = bounds.southWest;
  final northWest = Point(northEast.y, southWest.x);

  final distanceLatitude = northEast.x - southWest.x;
  final distanceLongitude = northEast.y - northWest.y;

  for (int i = 0; i < division; i++) {
    for (int j = 0; j < division; j++) {
      final newNorthEast = Point(
        southWest.x + (distanceLatitude * i) / division,
        southWest.y + (distanceLongitude * j) / division,
      );

      final newSouthWest = Point(
        southWest.x + (distanceLatitude * (i + 1)) / division,
        southWest.y + (distanceLongitude * (j + 1)) / division,
      );

      subBounds.add(GMULatLngBounds(newNorthEast, newSouthWest));
    }
  }

  return subBounds;
}