Library tutorials & articles

Writing GPS Applications in .NET: Part 1

Introduction

Sample Image - WritingGPSApplications1.jpgWhat is it that GPS applications need to be good enough to use in a commercial environment, such as in-car navigation? Also, how does the process of interpreting GPS data actually work? In this two-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application that works with a majority of GPS devices in the industry today.

One Powerful Sentence

This first part in the series will explore the task of interpreting raw GPS data. Fortunately, the task is simplified thanks to the National Marine Electronics Association (www.nmea.org) which introduced a standard for the industry now in use by a vast majority of GPS devices. To give developers a head start, I chose to use some Visual Studio.NET source code from my “GPS.NET Global Positioning SDK” component. (The code is stripped of features like multithreading and error handling for brevity.)

NMEA data is sent as comma-delimited “sentences” which contain information based on the first word of the sentence. There are over fifty kinds of sentences, yet an interpreter really only needs to handle a few to get the job done. The most common NMEA sentence of all is the “Recommended Minimum” sentence, which begins with “$GPRMC.” Here is an example:

$GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A

This one sentence contains nearly everything a GPS application needs: latitude, longitude, speed, bearing, satellite-derived time, fix status and magnetic variation.

Comments

  1. 29 Jun 2008 at 21:50

    Hi , 

    I need the same program as well.Can you find any information.Please contact me.

    tunc@te-mob.com

     

  2. 21 Aug 2007 at 11:19

     

    The checksum routine has been modified slightly to clarify the Select statement.

    The "$" case is used to initialise Checksum and the If statement in the Else case has been removed.  This works because Checksum = value gives the same result as Checksum = 0 Xor value when processing the first byte.

     

        ' Calculates the checksum for a sentence

        Public Function GetChecksum(ByVal sentence As String) As String

            ' Loop through all chars to get a checksum

            Dim Character As Char

            Dim Checksum As Integer = 0

            For Each Character In sentence

                Select Case Character

                    Case "$"c

                        ' Ignore the dollar sign

                        Checksum = 0

                    Case "*"c

                        ' Stop processing before the asterisk

                        Exit For

                    Case Else

                        ' XOR the checksum with this character's value

                        Checksum = Checksum Xor Convert.ToByte(Character)

                End Select

            Next

            ' Return the checksum formatted as a two-character hexadecimal

            Return Checksum.ToString("X2")

        End Function

  3. 21 Aug 2007 at 11:02

    The NMEA protocol specifies that the last parameter is immediately followed by "*" and a 2-cfharacter checksum.  For example, 3.45,"W"*1A is valid as is 200804,,*1A.  In the fist case there is data in the last parameter and in the second case, because the last parameter has been omitted. we effectively have "200804,," & "" & "*" & "1A".  That is the data string upto the second last parameter and it's following comma, the omitted final parameter, the asterisc to denote both end of data and the start of  the checksum, and finally the 2-character checksum.

    Jon's excellent articles give us the start for writing our code but does say that additional error trapping is required.

    My change to the GetWords function is:

        Public Function GetWords(ByVal sentence As String) As String()

            Dim temp As String

            temp = sentence.Substring(0, sentence.IndexOf("*")) & ",*"

            Return temp.Split(","c)

        End Function

  4. 19 Aug 2007 at 08:01

    Try my gps string parser http://www.gpsxml.com/gpsxml/service.asmx?op=GPS2XML

    I need somebody to test my mobile APP. You can download the cab file from http://gps.gpsxml.com/viewtopic.php?t=4

    Please feel free to give any comments, suggestions or ideas

    Thanks
    Imtiyaz Momin
    http://gps.gpsxml.com/
    imtu80@hotmail.com








  5. 16 Aug 2007 at 06:01

    I need somebody to test my mobile APP. You can download the cab file from http://gps.gpsxml.com/viewtopic.php?t=4
    Also, added new feature where I can upload picture from the phone using my application and the picture shows up on the trail where the picture was taken.
    Check it out at http://gps.gpsxml.com/tracker.cfm?userID=1
    Please feel free to give any comments, suggestions or ideas

    Thanks
    Imtiyaz Momin
    http://gps.gpsxml.com/
    imtu80@hotmail.com







  6. 28 Jun 2007 at 10:19

    I am a novice programmer and need to get my hands on some code for phone tracking which will plot a phones movement every (n) minutes then plot the position  on a map.

    Any help at all will be greatly appreciated.

    Can anyone please please help me.

    Thanks
    Nev

  7. 21 Jun 2007 at 02:48

    http://gps.imomin.com/tracker.cfm?userID=1

    Above link shows an example which I created for my brother for his carpc.
    It can covertly run on mobile device and send location information via internet.
    let me know what you think and anything can be done with my project.


    Imtiyaz Momin
    imtu80@hotmail.com
    http://www.imomin.com








  8. 10 Jun 2007 at 15:20

    Regarding with GPRMC message

    $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,,*1A

    Some antennas (like Leadtek) See quotes, transmitt the last parameter before * char like this

    $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,3.45,"W"*1A

    Other antennas (like Garmin), transmit the last parameter like this

    $GPRMC,040302.663,A,3939.7,N,10506.6,W,0.27,358.86,200804,3.45,"W",*1A

    Note that has a colon "," before * char.

    Please someone explain me this question.

    Thanks.

    Jean

  9. 19 Apr 2007 at 07:21

    Hi,

    Can I get the c# code for this nice article?

    Regards,
    Ravi






  10. 12 Apr 2007 at 12:31

    Well...as soon as you write a post you figure soething out.

    It seems that the error is only thrown when there isn't enough data in the nmea sentence because if I use this sentence

    $GPGSV,2,2,08,14,28,047,21,28,20,259,,19,16,156,26,23,07,254,41*71

    it seems to work fine. I think the problem is with the SNR for the first satellite in view as the previous NMEA didn't have a value for this.

    Hope this helps someone.

  11. 12 Apr 2007 at 12:23

    Nice article, very useful except I've come across a problem with the GPGSV sentences. If you try and run this code

    MyInterpreter.Parse("$GPGSV,2,1,08,11,78,132,,20,63,226,,01,46,102,,17,33,308,*71")

    It will throw an error (Conversion from string "*71" to type 'Integer' is not valid.)

    This is because of this line of code

    SignalToNoiseRatio =

    CType(Words(Count * 4 + 3), Integer)

    Does anyone know how to solve this problem as it's kind of a thorn in my side and I can't get rid of it.

    Cheers

    Jon

  12. 14 Mar 2007 at 21:31

    I like to write GPS navigating system pleas tell me what kind of hardware and signals I need, I am living in Sri Lanka, how I get that connection

  13. 23 Mar 2006 at 08:32

    If you require Ordnance Survey Grid References, I have written an article on how to do so using NMEA data derived from Jon Person's excellent NMEAinterpreter class.


    GPS- Deriving British Ordnance Survey Grid Referece from NMEA data

    AlexE


  14. 14 Mar 2006 at 13:08

    I spotted this slight error too and made the same correction as cprogrammingguru.
    However this led to a new error as the final word in the string contained the checksum.
    ie in the example sentence

    $GPGSV, 3, 1, 10, 24, 82, 023, 40, 05, 62, 285, 32, 01, 62, 123, 00, 17, 59, 229, 2870

    the final word would be 28
    70
    this caused an error when trying to convert this to an int32 in the line

    SignalToNoiseRatio = Convert.ToInt32(Words[Count * 4 + 3]);

    My solution was to remove the checksum part of the sentence in GetWords, before splitting the sentence
     
        public string[] GetWords(string sentence)
        {
            //remove the final * + checksum
            sentence = sentence.Substring(0, sentence.IndexOf("*"));
            //now split it up
            return sentence.Split(',');
        }


    Assuming that I'm not talking out of my rear, I hope this proves useful
    Alex
     























  15. 13 May 2005 at 18:11

    I love this product. Excellent Job on this product, Jon Person !. I'm really excited infact I am going to go buy and support your product 360%!... I just have to correct 1 minor error. I feel you should be aware or maybe your are already....don't know might have been a typo,... I'm not much of a VB coder but, I believe during the ParseGPGSV() function, which is suppose to parse the "Satellites in View" $GPGSV sentence.... If you look closesly. During the...


    Original Article: http://www.gpsdotnet.com/kb/article.aspx?id=10350
    Example Sentence: $GPGSV, 3, 1, 10, 24, 82, 023, 40, 05, 62, 285, 32, 01, 62, 123, 00, 17, 59, 229, 28*70


    Each Block consist of 4 words.. "24, 82, 023, 40"  ==  "PseudoRandomCode, Elevation, Azimuth, SignalToNoiseRatio"
    According to your Article... SNR values range from 0-50...where 50 means "Excellent Signal"...though SNR can go as high as 99, like you've stated.





    ' Yes. "Extract satellite information and report it" -- section.
    ' ERROR suspect


        Azimuth = CType ( Words ( Count * 4 + 2 ), Integer)
        SignalToNoiseRatio = CType( Words ( Count * 4 + 2 ), Integer)    
                                                                             '// ^--- Logical Bug, I believe it should be ....


    ' CORRECTION
        SignalToNoiseRatio = CType ( Words ( Count * 4 + 3), Integer)
                                                                             '// ^--- This would be correct.



    Otherwise I believe it would return the same value from the Azimuth extraction. So you wouldn't get any SNR information to be able to base precision correctly. For the future of dependability and reliability of code production, I post this correction. As far as the Signal Strength of the satellites, within the Notification, of the Event call to,...


             RaiseEvent SatelliteReceived ( PseudoRandomCode,  Azimuth,  Elevation,  SignalToNoiseRatio )


    I believe it would generate incorrect results...to what ever is going to be done with the SNR variable.
    Please feel free to e-mail me at deciphered_scripturez@yahoo.com for additional details...I really Thank you, Jon Person, for your hard work and time put into this and I really would LOVE to help as much as possible...I believe in your product. !    


                                                                                                                                                                  Thank You,
                                                                                                                                                                   -- cprogrammingguru

  16. 02 Apr 2005 at 20:37

    As I understand it, that should be fine... so long as you add a GPS receiver?

  17. 11 Jan 2005 at 13:13

    Hi
    Just curious, what kind of hardware and signal service will be required to make it happen?
    I have a ViewSonic V37 pocket PC. Will that be a good instrument for this? Please advice.
    Thanks
    Pankaj

  18. 08 Oct 2004 at 08:44

    Jon Person's article is a particularly interesting look into how GPS systems work.  I've been interested in GPS for a long time but not knowing how this new "black box" technology worked kept me away from delving into it.  After reading Jon's article I now realize that it's not nearly as difficult as I once thought.  I plan on buying his “GPS.NET Global Positioning SDK” component so I can begin writing applications utilizing GPS.  Who knows, perhaps I'll stumble onto a successful application with vertical market benefit.


    Thank you, Jon.  I look forward to your next article.


    Steve

  19. 01 Jan 1999 at 00:00

    This thread is for discussions of How to Write a GPS Application.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related podcasts

  • CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media

    CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!