iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (35)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

July 20, 2008
Wiki: A Solution to the Web Design Problem
About
 
July 19, 2008
Plurk or Twitter: Which one is Better?
About
 
July 19, 2008
Top 10 Social Networking Sites
About
 
July 19, 2008
Create Menus with Lists and CSS
About
 
July 17, 2008
Poll: What do you do when you can't design?
About
 
July 17, 2008
22 Reasons to Plurk
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /Visual Basic

Write Your Own GPS Applications: Part I 

  Views:    25217
  Votes:    31
by Jon Person 9/21/04 Rating: 

Synopsis:

What is it that GPS applications need to be good enough to use for 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.
Pages: firstback1 3 4 5 6 7 8 9 forwardlast
The Article

The Core of An Interpreter

The first step in making an NMEA interpreter is writing a method which does two things: separating each sentence into its individual words and 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

The next step is to perform actual extraction of information, starting with latitude and longitude. Latitude and longitude are stored in the form “DDD°MM’SS.S,” where D represents hours (also called “degrees”), M represents minutes and S represents seconds. Coordinates can be displayed in shorthand, such as “DD°MM.M’” or even “DD°.” The fourth word in the sentence, “3939.7,” shows the current latitude as hours and minutes (39°39.7’), except the numbers are squished together. The first two characters (39) represent hours and the remainder of the word (39.7) represents minutes. Longitude is structured the same way, except that the first three characters represent hours (105°06.6’). Words five and seven indicate the “hemisphere,” where “N” means “North,” “W” means “West” etc. The hemisphere is appended to the end of the numeric portion to make a complete measurement.
I’ve found that NMEA interpreters are much easier to work with they are event-driven. This is because data arrives in no particular order. An event-driven class gives the interpreter the most flexibility and responsiveness to an application. So, I’ll design the interpreter to report information using events. The first event, PositionReceived, will be raised whenever the current latitude and longitude are received. Listing 1-2 expands the interpreter to report the current position.

(Listing 1-2: The interpreter can now report the current latitude and longitude.)

'*******************************************************
'**  Listing 1-2.  Extracting information from a sentence
'*******************************************************
Public Class NmeaInterpreter

  ' Raised when the current location has changed
  Public Event PositionReceived(ByVal latitude As String, _                                ByVal longitude As String)

  ' Processes information from the GPS receiver
  Public Function Parse(ByVal sentence As String) As Boolean
    ' Look at the first word to decide where to go next
    Select Case GetWords(sentence)(0)
      Case "$GPRMC"      ' A "Recommended Minimum" sentence was found!
        Return ParseGPRMC(sentence)
      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

  ' Interprets a $GPRMC message
  Public Function ParseGPRMC(ByVal sentence As String) As Boolean
    ' Divide the sentence into words
    Dim Words() As String = GetWords(sentence)
    ' Do we have enough values to describe our location?
    If Words(3) <> "" And Words(4) <> "" And Words(5) <> "" And _       Words(6) <> "" Then
      ' Yes. Extract latitude and longitude
      Dim Latitude As String = Words(3).Substring(0, 2) & "°" ' Append hours
      Latitude = Latitude & Words(3).Substring(2) & """"      ' Append minutes
      Latitude = Latitude & Words(4)     ' Append the hemisphere
      Dim Longitude As String = Words(5).Substring(0, 3) & "°" ' Append hours
      Longitude = Longitude & Words(5).Substring(3) & """"     ' Append minutes
      Longitude = Longitude & Words(6)     ' Append the hemisphere
      ' Notify the calling application of the change
      RaiseEvent PositionReceived(Latitude, Longitude)
    End If
    ' Indicate that the sentence was recognized
    Return True
  End Function
End Class


One thing to watch out for here is that some GPS devices will report blank values when no information is known. Therefore, it’s a good idea to test each word for a value before parsing. If you need to type the degree symbol (°), hold down the Alt key and type “0176” on the numeric keypad.

 

Pages: firstback1 3 4 5 6 7 8 9 forwardlast
Attachments:
WritingGPSApplications1_src.zip [13570 byte] (VB.NET Source Code for Listings)

Similar/related articles:


 
  Sponsors