Developing with GPS data and devices

GPS library in the Mobile SDK

The GPS library reads and parses GPS positions from a connected COM port. The COM port can be a physical serial port, a virtual COM port bound to a GPS receiver via Bluetooth or USB, or a program COM port attached to a GPS intermediate driver on Windows Mobile devices. Please note that the GPS intermediate driver is available on Windows Mobile 5.0 and newer systems and allows more than one application to access the GPS at the same time. For additional information on the intermediate driver, see http://msdn.microsoft.com/en-us/library/ms850332.aspx.

It is also important to note that the ArcGIS Mobile GPS library only supports the NMEA protocol. ArcGIS Mobile supports the use of GPS receivers that do not output GPS positions in NMEA format through third party tools (such as Trimble GPS Controllerfor Trimble GPS receivers).

You should ensure that your GPS receiver is correctly configured and you know what COM port you wish to use before starting your ArcGIS Mobile application and opening a connection to the GPS receiver.

GPS components in the IDE toolbox

The Mobile SDK provides three .NET Components as part of the toolbox for designing mobile enterprise applications:

Each component is designed to perform the heavy lifting in managing connection to GPS receiver, parsing NMEA GPS sentences, displaying GPS on the Map, and providing an interface for leveraging GPS sentences elsewhere in your application.

SerialPortGpsConnection

The SerialPortGpsConnection manages the communication between the GPS device and your application. After establishing a connection to a GPS device, SerialPortGpsConnection decodes received positional information, packages it and broadcasts the decoded information to the mobile application inside meaningful event arguments. To use this component you must specify the name of the port with which the GPS device has been paired.

FileGpsConnection

The FileGpsConnection component simulates a GPS by reading an input file that contains positional information previously gathered from a GPS device. As the information is read, at an interval specified by the user, the FileGpsConnection decodes the positional information, packages it and broadcasts the decoded information to the mobile application inside meaningful event arguments. When the SentenceReceived event is fired the NMEASentenceEventArgs can be used to access the GPS information. The GPSDisplay component will automatically get the GPS information if it is properly linked to the GPSFileConnection. To use this component you must specify a valid file name containing the NMEA sentence positional information.

GpsDisplay

The GpsDisplay component synchronizes the information decoded by the GpsConnection and displays it within a map. To use this component you must specify the active GpsConnection (either SerialPortGpsConnection or FileGpsConnection) and the map to use. This component contains all the properties and settings used to control how the GPS positional information is displayed. See the object reference for details on each of the properties.

Getting started with GPS development

The first step in working with GPS, and perhaps the hardest, is to establish a connection between a COM port on your device and a GPS receiver. For mobile devices that have a built in receiver or for GPS receivers physically connected to your machine via a cable, this is usually not a problem. However, Bluetooth connections can be problematic due to the various hardware and software configurations. In either case, you should be able to follow the manufactures installation guide for your environment and establish a GPS connection to COM port on your device.

To start using GPS information in your application, add the SerialPortGpsConnection component from the ArcGIS Mobile Controls tab in Visual Studio to your project. The properties on this component configure the communication properties between your device and the receiver and include items such as the COM port, baud rate, etc. The common practice is to leave the default values and set the COM port to a value established above. To receive GPS information from the receiver you need to call SerialPortGpsConnection.Open within your code, which is usually called from an appropriate control such as a button or checkbox on your UI. To stop receiving information, call the corresponding Close method.

Working with GpsDisplay

The GPS location can be displayed on your map via the GpsDisplay component. Add this component to your project from the ArcGIS Mobile Controls tab in Visual Studio and set the GpsConnection property to the SerialPortGpsConnection that you previously added. When you run your application and open the GpsConnection the map will center on the GPS location and display the position with a marker.

Working with GPS information

In addition to displaying the GPS position on the map, you can also obtain the GPS information received from the connection. Each time a GPS sentence is received by the GpsConnection a GpsChanged event is fired. You can listen to this event and return a GpsEventArgs class. Due to the multi-threaded architecture of the components, you should include the appropriate code to handle thread pools as shown in the following example.

private void serialPortGpsConnection1_GpsChanged(object sender, GpsEventArgs e)
{
  if (InvokeRequired) 
    {
    Invoke(new GpsChangedEventHandler(serialPortGpsConnection1_GpsChanged),sender, e);
    return;
    }
  MessageBox.Show(e.Altitude); 
}

You can use the Latitude and Longitude properties on the GpsEventArgs class to get a GPS position and display this on your map, as an alternative to the GpsDisplay component, or for creating geometry in new features. If your map is not in WGS84 coordinates though you should use the SpatialReference.FromWGS84ToCoodinate method to project the returned coordinate.

GPS sample application

The Working with GPS in a Windows application sample illustrates how to read and visualize GPS data in an windows application.


9/20/2011