contains method

bool contains(
  1. LatLng point
)

Determines whether a given geographical point (LatLng) is within the bounds defined by two other geographical points: southwest (lower-left corner) and northeast (upper-right corner).

Implementation

bool contains(LatLng point) {
  final isLatitudeInBounds = point.latitude >= southwest.latitude &&
      point.latitude <= northeast.latitude;

  final bool isLongitudeInBounds;

  if (southwest.longitude <= northeast.longitude) {
    isLongitudeInBounds = point.longitude >= southwest.longitude &&
        point.longitude <= northeast.longitude;
  } else {
    isLongitudeInBounds = point.longitude >= southwest.longitude ||
        point.longitude <= northeast.longitude;
  }
  return isLatitudeInBounds && isLongitudeInBounds;
}