Coordinates constructor

Coordinates(
  1. double latitude,
  2. double longitude, {
  3. bool validate = false,
})

If you pass true with validate param then it will throw ArgumentError if latitude or longitude is invalid.

Implementation

Coordinates(this.latitude, this.longitude, {bool validate = false}) {
  if (validate) {
    if (!(latitude.isFinite && latitude.abs() <= 90)) {
      throw ArgumentError(
          'Invalid Latitude supplied, Latitude must be a number between -90 and 90');
    }

    if (!(longitude.isFinite && longitude.abs() <= 180)) {
      throw ArgumentError(
          'Invalid longitude supplied, Longitude must a number between -180 and 180');
    }
  }
}