LatLngBounds constructor

LatLngBounds(
  1. LatLng corner1,
  2. LatLng corner2
)

Create new LatLngBounds by providing two corners. Both corners have to be on opposite sites but it doesn't matter which opposite corners or in what order the corners are provided.

If you want to create LatLngBounds with raw values, use the LatLngBounds.unsafe constructor instead.

Implementation

factory LatLngBounds(LatLng corner1, LatLng corner2) {
  final double minX;
  final double maxX;
  final double minY;
  final double maxY;
  if (corner1.longitude >= corner2.longitude) {
    maxX = corner1.longitude;
    minX = corner2.longitude;
  } else {
    maxX = corner2.longitude;
    minX = corner1.longitude;
  }
  if (corner1.latitude >= corner2.latitude) {
    maxY = corner1.latitude;
    minY = corner2.latitude;
  } else {
    maxY = corner2.latitude;
    minY = corner1.latitude;
  }
  return LatLngBounds.unsafe(
    north: maxY,
    south: minY,
    east: maxX,
    west: minX,
  );
}