Esempio n. 1
0
        /// <summary>
        /// Retreives a GPS Coordinate from the specified GPS
        /// </summary>
        /// <param name="GPS">SerialPort that represents GPS</param>
        public static Coordinate GetCoordinates(SerialPort GPS)
        {
            if (!GPS.IsOpen)
            {
                GPS.Open();
            }
            string gpsReadout = String.Empty;

            while (!gpsReadout.StartsWith("$GPGGA") && !gpsReadout.StartsWith("$GPRMC"))
            {
                gpsReadout = GPS.ReadLine();
            }
            GPS.Close();

            double latitude;

            CoordinateComponent.CardinalDirection longDir;
            double longitude;

            CoordinateComponent.CardinalDirection latDir;
            string[] readout = gpsReadout.Split(',');

            try
            {
                if (gpsReadout.StartsWith("$GPGGA"))
                {
                    latitude  = CoordinateComponent.DegreeMinutesToDecimal(double.Parse(readout[2]));
                    latDir    = (CoordinateComponent.CardinalDirection)readout[3][0];
                    longitude = CoordinateComponent.DegreeMinutesToDecimal(double.Parse(readout[4]));
                    longDir   = (CoordinateComponent.CardinalDirection)readout[5][0];
                }
                else
                {
                    latitude  = CoordinateComponent.DegreeMinutesToDecimal(double.Parse(readout[3]));
                    latDir    = (CoordinateComponent.CardinalDirection)readout[4][0];
                    longitude = CoordinateComponent.DegreeMinutesToDecimal(double.Parse(readout[5]));
                    longDir   = (CoordinateComponent.CardinalDirection)readout[6][0];
                }
                return(new Coordinate(latitude, latDir, longitude, longDir));
            }
            catch
            {
                return(GetCoordinates(GPS));
            }
        }
Esempio n. 2
0
 public Coordinate(CoordinateComponent lat, CoordinateComponent lon)
 {
     Latitude  = lat;
     Longitude = lon;
 }