fromCoords static method

Geolocation? fromCoords(
  1. String? coords, [
  2. bool onlyWithCardinals = false
])

Implementation

static Geolocation? fromCoords(
  String? coords, [
  bool onlyWithCardinals = false,
]) {
  if (coords == null) return null;
  coords = coords.trim();
  if (coords.isEmpty) return null;

  // Separated by blanks, optionally after a `,` or `;` (`10.5N, 20.3E`).
  // A `,` not followed by a blank is a decimal separator (`10,5N`).
  var parts = coords.split(RegExp(r'\s*;\s*|,\s+|\s+'));
  if (parts.length < 2) return null;

  var lat = parseLatitudeOrLongitudeValue(parts[0], onlyWithCardinals);
  var long = parseLatitudeOrLongitudeValue(parts[1], onlyWithCardinals);

  return lat != null && long != null ? Geolocation(lat, long) : null;
}