Overview
Altitude
CourseOverGround
DecimalLatitude
DecimalLongitude
GPSBuffer
GPSDecoded Event
GPSStream
Latitude
LatitudeHemisphere
Longitude
LongitudeHemisphere
New1 (GPS-Object)
NumberOfSatellites
SpeedOverGround
Status
UTCDate
UTCTime
ChangeDatum
LatLonToUTM
New1 (GPS-Converter Object)
UTMToLatLon
WGS84LatLonToUTM
WGS84UTMToLatLon
Overview Top
The GPS library decodes a standard NMEA 0183 string received from the GPS receiver.
The main function of this library is GPSStream.
This function receives the string received from the GPS and when the string includes enough data it updates all the properties and raises the GPSDecoded event.
Using the Converter library which is also included in this library you can convert geographic coordinates from Lat/Lon format to UTM format (and vice versa) and from different datums.
The data from the GPS is received using the Serial library and the InputString method.
The following example demonstrates the most straightforward way to handle the GPS data.
Example: Add a GPS object named gps, a Serial object named Serial and a Converter object named converter.
Sub Globals
dim ll(0) as double, utm(0) as double
End Sub
Sub App_Start
Form1.Show
If cppc = true then port = 8 else port = 5 'Change it to fit your ports numbers.
Serial.New2(port,9600,"N",8,1)
Serial.PortOpen = true
gps.New1
converter.New1
AddTimer("Timer1")
Timer1.Interval = 1000
Timer1.Enabled = true
End Sub
Sub Timer1_Tick
if Serial.InBufferCount>0 then
gps.GPSStream(Serial.InputString)
end if
End Sub
Sub GPS_GPSDecoded
ListBox1.Clear
ListBox1.add("status: "& gps.status)
ListBox1.Add("Number Of Satellites: " & gps.NumberOfSatellites)
ListBox1.Add("Time: " & gps.UTCTime)
ListBox1.add("lat: " & gps.latitude)
ListBox1.add("lon: " & gps.longitude)
ListBox1.add("dlat: "& gps.DecimalLatitude)
ListBox1.Add("dlon: " & gps.DecimalLongitude)
ListBox1.add("speed: "& gps.speedoverground)
utm() =Converter.WGS84LatLonToUTM(gps.DecimalLatitude,gps.DecimalLongitude)
ListBox1.Add("XZone: " & utm(0))
ListBox1.Add("UTMX: " & utm(1))
ListBox1.Add("YZone: " & chr(utm(2)))
ListBox1.Add("UTMY: " & utm(3))
End Sub
Altitude Top
Returns the altitude in meters above sea level.
Note that this value may be incorrect even when other values are correct.
Syntax: Altitude
CourseOverGround Top
Returns the current course direction.
Syntax: CourseOverGround
DecimalLatitude Top
Returns the Latitude formatted as dd.dddd
The number will be positive for the northern hemisphere and negative otherwise.
Syntax: DecimalLatitude
DecimalLongitude Top
Returns the DecimalLongitude formatted as ddd.dddd
The number will be positive for the east hemisphere and negative otherwise.
Syntax: DecimalLongitude.
GPSBuffer Top
Gets or sets the string the has not yet been decoded.
This property should not be used normally, but rather be updated by the GPSStream method.
Syntax: GPSBuffer
GPSDecoded Event Top
This event is raised by the GPSStream function after it succeeded decoding new data.
Syntax: GPSDecoded
GPSStream Top
Adds the data received from the GPS to the buffer.
If there is enough data, the data will be decoded and the GPSDecoded event will be raised.
Syntax: GPSStream (GPSDate As String)
Latitude Top
Returns the Latitude formatted as: ddmm.mm
Syntax: Latitude
LatitudeHemisphere Top
Returns "N" or "S" for the Latitude hemisphere.
Syntax: LatitudeHemisphere
Longitude Top
Returns the Longitude formatted as dddmm.mm
Syntax: Longitude
LongitudeHemisphere Top
Returns "E" or "W" for the Longitude hemisphere.
Syntax: LongitudeHemisphere
New1 (GPS-Object) Top
Initializes a GPS object.
Syntax: New1
NumberOfSatellites Top
Returns the number of satellites received by the GPS.
Syntax: NumberOfSatellites
SpeedOverGround Top
Returns the speed in knots (nautical miles).
1 knot equals 1.151 miles/hour and 1.852 kilometers/hour.
Syntax: SpeedOverGround
Status Top
Returns "A" if the GPS status is ok and "V" if there is any warning.
It is important to verify the status as if it is not "A", data could be wrong.
Syntax: Status
UTCDate Top
Returns the UTC date formatted as ddmmyy.
Syntax: UTCDate
UTCTime Top
Returns the UTC time formatted as hhmmss.
Syntax: UTCTime
ChangeDatum Top
Returns the value of the given coordinates in a different datum.
The data needed for the different datums can be found here:
http://www.colorado.edu/geography/gcraft/notes/datum/edlist.html
Syntax: ChangeDatum (Lat, Lon, From_a, From_f, To_a, To_f, Dx, Dy, Dz) As Double()
All arguments are of type Double.
Lat - The Latitude of the source coordinate. (dd.dddd)
Lon - The Longitude of the source coordinate. (ddd.dddd)
From_a - The semi-major axis of the source ellipsoid.
From_f - The flattening of the source ellipsoid.
To_a - The semi-major axis of the target ellipsoid.
To_f - The flattening of the target ellipsoid.
Dx - The change in x between the source and the target datum. (Dx of the source - Dx of
the target).
Dy - The change in y between the source and the target datum.
Dz - The change in z between the source and the target datum.
The function returns an array of two numbers:
0 - The Latitude value. (dd.dddd)
1 - The Longitude value. (ddd.dddd)
The following example converts the coordinates from WGS84 to European Datum 1950
(England).
Example:
Sub Globals
dim ll(0) as double
End Sub
Sub App_Start
converter.New1
lat = 32.5555
lon = 35.2222
ll() = converter.ChangeDatum(
lat,lon,6378137,1/298.257223563,6378388,1/297,86,96,120)
msgbox("Lat: " & ll(0) & crlf & "Lon: " & ll(1))
End Sub
LatLonToUTM Top
Converts a Lat/Lon formatted coordinate to an UTM formatted coordinate.
Use WGS84LatLonToUTM when using the WGS84 datum.
Syntax: LatLonToUTM (a As Double, f As Double, Lat As Double, Lon As Double) As Double()
a - The semi-major axis of the ellipsoid.
f - The flattening of the ellipsoid.
Lat - The Latitude of the coordinate. (dd.dddd)
Lon - The Longitude of the coordinate. (ddd.dddd)
The function returns an array of four numbers:
0 - The X zone.
1 - The X value.
2 - The ASCII code of the Y zone.
3 - The Y value.
Example:
Sub Globals
dim utm(0) as double
End Sub
Sub App_Start
converter.New1
lat = 32.5555
lon = 35.2222
utm() = converter.LatLonToUTM(6378388,1/297,lat,lon)
msgbox("XZone: " & utm(0) & " X: " & utm(1) & " YZone: " &
chr(utm(2)) & " Y: " & utm(3))
End Sub
New1 (GPS-Converter Object) Top
Initializes a Converter object.
Syntax: New1
UTMToLatLon Top
Converts an UTM formatted coordinate to a Lat/Lon formatted coordinate.
Use WGS84UTMToLatLon when using the WGS84 datum.
Syntax: UTMToLatLon (a As Double, f As Double, UTMXZone As Int32, Easting As Double, NorthHemisphere As Boolean, Northing As Double) As Double()
a - The semi-major axis of the ellipsoid.
f - The flattening of the ellipsoid.
UTMXZone - The X zone.
Easting - The easting (x) value.
NorthHemisphere - True for the northern hemisphere and false for the southern hemisphere.
Northing - The northing (y) value.
The function returns an array of two numbers:
0 - The Latitude value. (dd.dddd)
1 - The Longitude value. (ddd.dddd)
Example:
Sub Globals
dim ll(0) as double
End Sub
Sub App_Start
converter.New1
utmX = 654321
utmY = 3764322
ll() = converter.UTMToLatLon(6378388, 1/297, 36, utmX, true,
utmY)
msgbox("Lat: " & ll(0) & " Lon: " & ll(1))
End Sub
WGS84LatLonToUTM Top
Converts a Lat/Lon formatted coordinate to an UTM formatted coordinate using the
WGS84 datum.
Syntax: WGS84LatLonToUTM (Lat As Double, Lon As Double) As Double()
Lat - The Latitude of the coordinate. (dd.dddd)
Lon - The Longitude of the coordinate. (ddd.dddd)
The function returns an array of four numbers:
0 - The X zone.
1 - The X value.
2 - The ASCII code of the Y zone.
3 - The Y value.
WGS84UTMToLatLon Top
Converts an UTM formatted coordinate to a Lat/Lon formatted coordinate using the
WGS84 datum.
Syntax: WGS84UTMToLatLon (UtmXZone As Int16, Easting As Double, NorthHemisphere As Boolean, Northing As Double) As Double()
UTMXZone - The X zone.
Easting - The easting (x) value.
NorthHemisphere - True for the northern hemisphere and false for the southern hemisphere.
Northing - The northing (y) value.
The function returns an array of two numbers:
0 - The Latitude value. (dd.dddd)
1 - The Longitude value. (ddd.dddd