LocationDescription.fromString constructor

LocationDescription.fromString(
  1. String line
)

Implementation

factory LocationDescription.fromString(String line) {
  final parts = line.split('\t');
  final countryCodes = parts[0].split(',');
  final name = parts[2];
  final comments = parts.length > 3 ? parts[3] : '';

  final match = _geoLocationRe.firstMatch(parts[1])!;
  final latSign = match.group(1) == '+' ? 1 : -1;
  final latDeg = int.parse(match.group(2)!);
  final latMinutes = int.parse(match.group(3)!);
  final latSecondsRaw = match.group(4);
  final latSeconds = latSecondsRaw != null ? int.parse(latSecondsRaw) : 0;

  final longSign = match.group(5) == '+' ? 1 : -1;
  final longDeg = int.parse(match.group(6)!);
  final longMinutes = int.parse(match.group(7)!);
  final longSecondsRaw = match.group(8);
  final longSeconds = longSecondsRaw != null ? int.parse(longSecondsRaw) : 0;

  final latitude = latSign * (latDeg + (latMinutes + (latSeconds / 60)) / 60);
  final longitude =
      longSign * (longDeg + (longMinutes + (longSeconds / 60)) / 60);

  return LocationDescription(
      name, countryCodes, latitude, longitude, comments);
}