offset method

LatLng offset(
  1. LatLng offset
)

Returns a new LatLng instance offset by the given LatLng. Asserts that the operation does not cross the poles.

Implementation

LatLng offset(LatLng offset) {
  final double newLatitude = latitude + offset.latitude;
  assert(
    newLatitude >= -90.0 && newLatitude <= 90.0,
    'Latitude after applying offset must be between -90 and 90 degrees.',
  );

  // Handle longitude wrap-around (across the 180th meridian)
  double newLongitude = longitude + offset.longitude;
  newLongitude = (newLongitude + 180) % 360 - 180;

  return LatLng(latitude: newLatitude, longitude: newLongitude);
}