private static void GpsDataReceived(GpsPoint gpsPoint) { var lat = gpsPoint.Latitude.ToString("F4"); var lon = gpsPoint.Longitude.ToString("F4"); Debug.Print("Lat/long: " + lat + ", " + lon); }
private void ProcessBytes(string gpsData) { while (gpsData.IndexOf('\n') != -1) { var parts = gpsData.Split('\n'); _data += parts[0]; _data = _data.Trim(); if (_data != string.Empty) { if (_data.IndexOf("$GPRMS") != 0) { int g = 9; } if (_data.IndexOf("$GPRMC") == 0) { // Debug.Print("GOT $GPRMC LINE"); if (GpsData != null) { var gpsPoint = GprmcParser.Parse(_data); if (gpsPoint == null) { continue; } var isOk = true; if (_lastPoint != null) { var distance = GeoDistanceCalculator.GetDistanceInMiles(gpsPoint.Latitude, gpsPoint.Longitude, _lastPoint.Latitude, _lastPoint.Longitude); double distInFeet = distance * 5280; // Debug.Print("distance = " + distance + " mi (" + distInFeet + " feet)"); if (distance < _minDistanceBetweenPoints) { // Too close to the last point....don't raise the event isOk = false; } var timeDelta = (DateTime.Now - _lastDateTime); if (timeDelta.Seconds > 60) { // A minute has gone by, so update isOk = true; _lastDateTime = DateTime.Now; } } _lastPoint = gpsPoint; // Raise the event if (isOk) { GpsData(gpsPoint); } } } RawLine?.Invoke(_data); } gpsData = parts[1]; _data = string.Empty; } _data += gpsData; }