void GpsStatus.INmeaListener.OnNmeaReceived(long timestamp, string?message) #endif { _isNmeaSupported = true; if (message != null) { NmeaMessage?.Invoke(this, message); } }
void ILocationListener.OnLocationChanged(Location location) { if (location.Provider != LocationManager.GpsProvider) { Accuracy = float.NaN; return; } Accuracy = location.HasAccuracy ? location.Accuracy : float.NaN; if (_isNmeaSupported) { return; } // Not all Android devices support reporting NMEA, so we'll fallback to just generating // simple RMC and GGA message so the provider continues to work across multiple devices // $GPRMC: List <string> values = new List <string>(12); values.Add("$GPRMC"); DateTimeOffset d = DateTimeOffset.FromUnixTimeMilliseconds(location.Time); values.Add(d.ToString("hhmmss")); values.Add("A"); var lat = Math.Floor(Math.Abs(location.Latitude)); var latfrac = (Math.Abs(location.Latitude) - lat) * 60; values.Add($"{lat.ToString("00")}{latfrac.ToString(CultureInfo.InvariantCulture)}"); values.Add(location.Latitude < 0 ? "S" : "N"); var lon = Math.Floor(Math.Abs(location.Longitude)); var lonfrac = (Math.Abs(location.Longitude) - lon) * 60; values.Add($"{lon.ToString("000")}{lonfrac.ToString(CultureInfo.InvariantCulture)}"); values.Add(location.Longitude < 0 ? "W" : "E"); values.Add(location.HasSpeed ? location.Speed.ToString(CultureInfo.InvariantCulture) : ""); values.Add(location.HasBearing ? location.Bearing.ToString(CultureInfo.InvariantCulture) : ""); values.Add(d.ToString("ddMMyy")); values.Add(""); //Variation values.Add(""); //East/West NmeaMessage?.Invoke(this, string.Join(",", values) + "\n"); // $GPGGA: int satellites = 0; if (location.Extras != null && location.Extras.ContainsKey("satellites")) { satellites = Convert.ToInt32(location.Extras.Get("satellites")); } values = new List <string>(13); values.Add("$GPGGA"); values.Add(d.ToString("hhmmss")); values.Add($"{lat.ToString("00")}{latfrac.ToString(CultureInfo.InvariantCulture)}"); values.Add(location.Latitude < 0 ? "S" : "N"); values.Add($"{lon.ToString("000")}{lonfrac.ToString(CultureInfo.InvariantCulture)}"); values.Add(location.Longitude < 0 ? "W" : "E"); values.Add("1"); //Fix Quality: values.Add(satellites.ToString()); //Number of Satellites values.Add(""); //HDOP values.Add(location.HasAltitude ? location.Altitude.ToString(CultureInfo.InvariantCulture) : ""); values.Add("M"); //Altitude units values.Add(""); //Height of geoid above WGS84 ellipsoid values.Add(""); //Geoid height units values.Add(""); //Time since last DGPS update values.Add(""); //DGPS reference station id NmeaMessage?.Invoke(this, string.Join(",", values) + "\n"); }