parse method

  1. @override
GeoParsedResult? parse(
  1. Result result
)
override

Attempts to parse the raw Result's contents as a particular type of information (email, URL, etc.) and return a ParsedResult encapsulating the result of parsing.

@param theResult the raw Result to parse @return ParsedResult encapsulating the parsing result

Implementation

@override
GeoParsedResult? parse(Result result) {
  final rawText = ResultParser.getMassagedText(result);
  final matcher = _geoUrlPattern.firstMatch(rawText);
  if (matcher == null) {
    return null;
  }

  final query = matcher.group(4);

  double latitude;
  double longitude;
  double altitude;
  try {
    latitude = double.parse(matcher.group(1)!);
    if (latitude > 90.0 || latitude < -90.0) {
      return null;
    }
    longitude = double.parse(matcher.group(2)!);
    if (longitude > 180.0 || longitude < -180.0) {
      return null;
    }
    if (matcher.group(3) == null) {
      altitude = 0.0;
    } else {
      altitude = double.parse(matcher.group(3)!);
      if (altitude < 0.0) {
        return null;
      }
    }
  } catch (_) {
    //on NumberFormatException
    return null;
  }
  return GeoParsedResult(latitude, longitude, altitude, query);
}