Add Ons - DevSource
DevSource: Microsoft Developer Resource DevSource Home Sponsored by Microsoft Home Add Ons Architecture Languages Techniques Using VS Forums
Home arrow Add Ons arrow Get (Un)Lost: Connect .NET Apps with GPS Data
Get (Un)Lost: Connect .NET Apps with GPS Data
By Peter Aitken

Rate This Article: Add This Article To:

Review: GPS Toolkit.Net provides an API that makes it easy to add location support to your .NET applications.

GPS, the Global Positioning System, is really cool stuff. A network of satellites orbits the earth, broadcasting precisely timed signals. A GPS receiver picks up those signals, processes them, and — voilá! — you have your position within a dozen meters or so.

GPS uses have been spreading wildly. They started in the expected places, such as ships and airplanes. They spread to cars and then to pocket-size handheld units. Now it's even in some cell phones. Where next?

ADVERTISEMENT

Your computer, that's where! GPS units are specialized stand-alone units, but a lot of them are providing some form of interface to permit connection with other equipment. When a computer can talk to a GPS receiver, a world of possibilities opens up. Imagine your company's sales reps viewing client locations, so they can better estimate travel time. How about a service technician using her laptop to determine the best route to the next call? Or a taxi driver who doesn't get lost on the way to pick up a customer?

Scientific Component's GPS Toolkit.Net provides an API for interfacing your .Net programs with GPS receivers, and it greatly simplifies the task of writing GPS-aware apps. The GPS receiver must support the NMEA 0183 or Garmin protocols and have either a serial (RS-232) or Bluetooth interface. USB units are not supported, although that is promised for the future. These two protocols provide overlapping but not identical capabilities, so what you can do with the toolkit depends on which protocol your GPS receiver supports.

GPS programming requires an understanding of GPS concepts. At its heart, GPS provides you with an instantaneous position — information on your location in terms of latitude, longitude, and altitude. From this foundation, a lot of useful information can be determined:

  • Your track, the record of your positions over some time period shows where you have been.
  • Your course, comparing your current position with your previous position shows the direction in which you are moving.
  • Your speed, calculated using the distance between your most recent two positions and the time between them.

GPS units also provide a variety of other capabilities. For example, you can define waypoints, a specific location, such as your favorite fishing spot, that you want to remember. You can also define routes, a series of waypoints that takes you from one location to another.

Most GPS units come equipped with maps, a visual representation of geography that lets you view position, tracks, and other information in a meaningful way. Knowing that your position is 74 degrees 32 minutes West and 36 degrees 12 minutes north is not too useful; seeing that you are just east of Anytown is what you want!

GPSToolKit does not let you access map data from your GPS unit. This is not a flaw; it's just the way things work. Your application can use its own map data in conjunction with the information from your GPS unit.

GPS maps are available from a wide variety of sources. Some are available for free download, but the better ones, showing more details and points of interest, are more likely to be sold. A Google search for "GPS maps" will turn up lots of sources.

Use of the toolkit is straightforward. After installation, the SciCom.GPSToolKit namespace becomes available to your projects. You create an instance of the GPSToolKit class and access all of the API's functionality through that instance. You have access to properties for things such as position, speed, and course. Methods let you do things such as adding routes, getting tracks, and defining waypoints.

Particularly useful, in my opinion, are the GPSToolKit events which let your program respond to things such as the position being updated or the GPS unit disconnecting.

The API calls are well thought out. You can auto-detect a connected GPS — or more than one, as the API supports multiple GPS receivers — with a call to AutoDetectGPS(). Or, you can open a GPS unit on a specified port, like this:

myGPSToolKit.AutoDetectGPS(PortNumber)

When the GPS unit updates its position, the GPSToolkit fires the OnPositionUpdate method. This enables your program to always stay updated with the latest position info. Here's a code example to show how you might do this:

Private Sub myGPSToolKit_OnPositionUpdate(ByVal sender As Object, _
    ByVal e As SciCom.GPSToolKit.PositionUpdateEventArgs) _
    Handles myGPSToolKit.PositionUpdate
' Lat/Lon
If e.Position.IsValid = True Then
    Dim lat As Latitude
    Dim lon As Longitude
    lat = e.Position.Latitude
    lon = e.Position.Longitude
    ' Decimal degrees
    txtLat.Text = lat.ToDecimalDegreesString()
    txtLon.Text = lon.ToDecimalDegreesString()
Else
    txtLat.Text = "No Latitude Data"
    txtLon.Text = "No Latitude Data"
End If
' Altitude
Dim alt As Altitude = e.Position.Altitude
If alt.IsValid = True Then
    txtAlt.Text = alt.ValueInMeters.ToString("0.0") + " m"
Else
    txtAlt.Text = "No Altitude Data"
End If
' Speed
Dim speed As Speed = e.Speed
If speed.IsValid = True Then
    txtSpeed.Text = speed.ValueInKPH.ToString("0.0") + " kph"
Else
    txtSpeed.Text = "No Speed Data"
End If
' True course 
Dim trueCourse As Angle = e.TrueCourse
If trueCourse.IsValid = True Then
    txtTrueCourse.Text = trueCourse.ValueInDegrees.ToString()
Else
    txtTrueCourse.Text = "No Course Data"
End If
End Sub

GPS programming is rather specialized, and anyone who tries to tackle it from scratch has my sympathy. Why not take advantage of the experience and expertise of others? GPS provides a full-featured API that can save you many hours of development time.

GPS Toolkit.Net is available in versions for Visual Studio 2003/CLR 1.1 and Visual Studio 2005/CLR 2.0. A single developer license permitting royalty-free distribution of applications costs $299.00.




Discuss Get (Un)Lost: Connect .NET Apps with GPS Data
 
>>> Be the FIRST to comment on this article!
 

 
 
>>> More Add Ons Articles          >>> More By Peter Aitken
 



Microsoft's Future: A Chat With Their CTO, Barry Briggs

Play Video >

All Videos >

Julia explores the Robotics Studio!

Read now >

Messages to Bill Gates!

Read now >

View Now
DevSource RSS FEEDS
XML Want an easy way to keep up with breaking tech news? And the Get DevSource headlines delivered to your desktop with RSS.