Parasing a GPS String in C#

Hey Guys,

I have GPS Device in my mobile phone, I get the following data from the device.
What is the best and most effcient way to parase the GPS Strig to get Lat and Lng?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
What is the layout of the string?
In general, the longitude and latitude are contained in th GPGGA sentences. However, your data does not match NEMA sentence definitions. Can you get encoding information from the Manufacturer's site?

Just an FYI - If you have not already seen it, there's the NEMA mapping for the GPGGA sentence.

The most important NMEA sentences include the GGA which provides the current Fix data, the RMC which provides the minimum gps sentences information, and the GSA which provides the Satellite status data.

GGA - essential fix data which provide 3D location and accuracy data.


     GGA          Global Positioning System Fix Data
     123519       Fix taken at 12:35:19 UTC
     4807.038,N   Latitude 48 deg 07.038' N
     01131.000,E  Longitude 11 deg 31.000' E
     1            Fix quality: 0 = invalid
                               1 = GPS fix (SPS)
                               2 = DGPS fix
                               3 = PPS fix
                         4 = Real Time Kinematic
                         5 = Float RTK
                               6 = estimated (dead reckoning) (2.3 feature)
                         7 = Manual input mode
                         8 = Simulation mode
     08           Number of satellites being tracked
     0.9          Horizontal dilution of position
     545.4,M      Altitude, Meters, above mean sea level
     46.9,M       Height of geoid (mean sea level) above WGS84
     (empty field) time in seconds since last DGPS update
     (empty field) DGPS station ID number
     *47          the checksum data, always begins with *

If the height of geoid is missing then the altitude should be suspect. Some non-standard implementations report altitude with respect to the ellipsoid rather than geoid altitude. Some units do not report negative altitudes at all. This is the only sentence that reports altitude.

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Bob LearnedCommented:
You can use the Microsoft.VisualBasic.FileIO.TextFieldParser to parse comma-delimited files to get the entries, looking for the GGA entries the Jim so carefully pointed out.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualBasic.FileIO;
public class CsvFileReader
  /// <summary>
  /// Read a CSV file, and add each line to a list of string arrays.
  /// </summary>
  /// <param name="fileName">The file to parse</param>
  /// <returns>A list of string arrays, which are the fields for the file</returns>
  public List<String[]> ReadFile(string fileName)
    // Initialize the return values
    List<String[]> list = new List<string[]>();
    errorLines = new List<int>();
    using (TextFieldParser parser = new TextFieldParser(fileName))
      // Setup the comma-delimited file parser.
      parser.TextFieldType = FieldType.Delimited;
      parser.Delimiters = new String[] { "," };
      while (!parser.EndOfData)
          // Read the comma-delimited text as fields into a string array.
          string[] input = parser.ReadFields();
          // Collect all the lines as fields.
        catch (MalformedLineException ex)
          Console.WriteLine("Error:  " + (int)ex.LineNumber);
    return list;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bob LearnedCommented:
Ok, this question is a perfect example of disrespecting experts.  First, it doesn't even recognize the efforts of Jim to describe the text, and then it gives it a "B" grade.  I mean, what did you expect that you didn't get?

.NET Zone Advisor
sonu19Author Commented:
Let's see!

Jim did put a lot of effort in to this, but I already knew what he answered. I understand the GPS output!

You answer seems correct and what I was looking.
The reason you got an B grade even though your code is correct, but you didn't not answer the question of parasing a string rather you answered opening a files the parasing.

No disrespect, I got an answer to my question, even before your post. I still gave you the points.

I don't have anything else, but respect to all the the Experts!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.