parseLatitudeOrLongitudeValue static method
num?
parseLatitudeOrLongitudeValue(
- String? s, [
- bool onlyWithCardinals = false
])
Implementation
static num? parseLatitudeOrLongitudeValue(String? s,
[bool onlyWithCardinals = false]) {
if (s == null) return null;
var match = geolocationFormat.firstMatch(s);
if (match == null) return null;
var signal = match.group(1);
var number = match.group(2);
var cardinal = match.group(3);
if (signal != null && signal.isNotEmpty) {
if (onlyWithCardinals) return null;
return double.parse('$signal$number');
} else if (cardinal != null && cardinal.isNotEmpty) {
cardinal = cardinal.toUpperCase();
switch (cardinal) {
case 'N':
return double.parse('$number');
case 'S':
return double.parse('-$number');
case 'E':
return double.parse('$number');
case 'W':
return double.parse('-$number');
}
}
if (onlyWithCardinals) return null;
return number != null ? double.parse(number) : null;
}