parseNMEA static method
- String nmeaSentence
Parses an NMEA sentence into a GpsCoordinates
object.
See https://shadyelectronics.com/gps-nmea-sentence-structure.
Implementation
static GpsCoordinates? parseNMEA(String nmeaSentence) {
final parts = nmeaSentence.split(",");
final tag = parts.first;
if (tag.endsWith("GGA")) {
return GpsCoordinates(
latitude: _nmeaToDecimal(double.tryParse(parts[2]) ?? 0.0),
longitude: _nmeaToDecimal(double.tryParse(parts[4]) ?? 0.0),
altitude: double.tryParse(parts[9]) ?? 0.0,
);
} else if (tag.endsWith("RMC")) {
return GpsCoordinates(
latitude: _nmeaToDecimal(double.tryParse(parts[3]) ?? 0.0),
longitude: _nmeaToDecimal(double.tryParse(parts[5]) ?? 0.0),
);
} else if (tag.endsWith("GLL")) {
return GpsCoordinates(
latitude: _nmeaToDecimal(double.tryParse(parts[1]) ?? 0.0),
longitude: _nmeaToDecimal(double.tryParse(parts[3]) ?? 0.0),
);
} else {
return null;
}
}