[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
Reading Latitude and Longitude
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.
[VB.NET]
If you need to type the degree symbol (°), hold down the Alt key and type “0176” on the numeric keypad.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
Reading Latitude and Longitude
Reading 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.
[VB.NET]
'*******************************************************
'** 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)
' 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
If you need to type the degree symbol (°), hold down the Alt key and type “0176” on the numeric keypad.
Written By Jon Person (http://www.gpsdotnet.com)
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
