Writing Your Own GPS Applications: Part I

“I am continually amazed by how little code is required to use atomic clocks in satellites 11,000 miles above my head.”

What is it that GPS applications need to be good enough to handle 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” that 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.

The Core of An Interpreter

The first step in making an NMEA interpreter is writing a method that does two things: separating each sentence into its individual words and then examining the first word to figure out what information is available to extract. Listing 1-1 shows the start of the interpreter class.

Listing 1-1: The core of an NMEA interpreter is a function which divides NMEA sentences into individual words.


‘*******************************************************
‘** Listing 1-1. The core of an NMEA interpreter
‘*******************************************************
Public Class NmeaInterpreter
‘ Processes information from the GPS receiver
Public Function Parse(ByVal sentence As String) As Boolean
‘ Divide the sentence into words
Dim Words() As String = GetWords(sentence)
‘ Look at the first word to decide where to go next
Select Case Words(0)
Case “$GPRMC” ‘ A “Recommended Minimum” sentence was found!
‘ Indicate that the sentence was recognized
Return True
Case Else
‘ Indicate that the sentence was not recognized
Return False
End Select
End Function
‘ Divides a sentence into individual words
Public Function GetWords(ByVal sentence As String) As String()
Return sentence.Split(“,”c)
End Function
End Class

More by Author

Must Read