setLongitude method
void
setLongitude({})
Method to set the longitude in degrees, minutes and seconds.
@param degrees The degrees of longitude to set between 0° and 180°. As an example 74 would be set for Lakewood, NJ. An IllegalArgumentException will be thrown if the value exceeds the limits. @param minutes minutes of arc @param seconds seconds of arc @param direction E for east of the Prime Meridian or W for west of it. An IllegalArgumentException will be thrown if the value is not E or W.
Implementation
void setLongitude(
{int? degrees,
int? minutes,
double? seconds,
String? direction,
double? longitude}) {
if (longitude != null) {
if (longitude > 180 || longitude < -180) {
throw ArgumentError("Longitude must be between -180 and 180");
}
_longitude = longitude;
} 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 longTemp = degrees + ((minutes + (seconds / 60.0)) / 60.0);
if (longTemp > 180 || _longitude < 0) {
//FIXME An exception should be thrown if degrees, minutes or seconds are negative
throw ArgumentError(
"Longitude must be between 0 and 180. Use a direction of W instead of negative.");
}
if (direction == "W") {
longTemp *= -1;
} else if (direction != "E") {
throw ArgumentError("Longitude direction must be E or W");
}
_longitude = longTemp;
}
}