setLatitude method

void setLatitude({
  1. int? degrees,
  2. int? minutes,
  3. double? seconds,
  4. String? direction,
  5. double? latitude,
})

Method to set the latitude in degrees, minutes and seconds.

@param degrees The degrees of latitude to set between 0° and 90°. For example 40 would be used for Lakewood, NJ. An IllegalArgumentException will be thrown if the value exceeds the limit. @param minutes minutes of arc @param seconds seconds of arc @param direction N for north and S for south. An IllegalArgumentException will be thrown if the value is not S or N.

Implementation

void setLatitude(
    {int? degrees,
    int? minutes,
    double? seconds,
    String? direction,
    double? latitude}) {
  if (latitude != null) {
    if (latitude > 90 || latitude < -90) {
      throw ArgumentError("Latitude must be between -90 and  90");
    }
    _latitude = latitude;
  } else if (degrees == null ||
      minutes == null ||
      seconds == null ||
      direction == null) {
    throw ArgumentError(
        "Longitude must be between 0 and  180.  Use a direction of W instead of negative.");
  } else {
    double tempLat = degrees + ((minutes + (seconds / 60.0)) / 60.0);
    if (tempLat > 90 || tempLat < 0) {
      //FIXME An exception should be thrown if degrees, minutes or seconds are negative
      throw ArgumentError(
          "Latitude must be between 0 and  90. Use direction of S instead of negative.");
    }
    if (direction == "S") {
      tempLat *= -1;
    } else if (direction != "N") {
      throw ArgumentError("Latitude direction must be N or S");
    }
    _latitude = tempLat;
  }
}