18 lines
707 B
Dart
18 lines
707 B
Dart
/// Convert decimal coordinate to degrees minutes seconds (DMS)
|
|
String convertDecimalToDMS(double decimalValue) {
|
|
bool isNegative = decimalValue < 0;
|
|
double absoluteValue = decimalValue.abs();
|
|
|
|
int degrees = absoluteValue.toInt();
|
|
double minutesDecimal = (absoluteValue - degrees) * 60;
|
|
int minutes = minutesDecimal.toInt();
|
|
double secondsDecimal = (minutesDecimal - minutes) * 60;
|
|
double seconds = double.parse(secondsDecimal.toStringAsFixed(2));
|
|
|
|
String direction = isNegative
|
|
? (decimalValue < 0 ? 'W' : 'S')
|
|
: (decimalValue >= 0 ? (degrees != 0 ? 'N' : 'E') : '');
|
|
|
|
// return formatted string
|
|
return '${degrees.abs()}° ${minutes.abs()}\' ${seconds.abs()}" $direction';
|
|
} |