Skip to content

Commit

Permalink
Merge branch 'main' into addLocationEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljosua1 authored Oct 31, 2024
2 parents 595017a + 3c18004 commit 3d6b4b5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions maplibre_gl_platform_interface/lib/src/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,26 @@ class LatLngBounds {
return <dynamic>[southwest.toJson(), northeast.toJson()];
}

/// 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).
///
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;
}

@visibleForTesting
static LatLngBounds? fromList(dynamic json) {
if (json == null) {
Expand Down

0 comments on commit 3d6b4b5

Please sign in to comment.