Click or drag to resize

The IGps Interface

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release

After reading this tutorial you should be able to create a sample application that will follow the current position (and rotate to the current heading) of a given GPS device.

Note Note

The code in this tutorial will be used as the framework for the following tutorials:

  • Using a Navigator
  • Using Notifications and Events
  • Using an XmlWaveAnnouncer
  • Using a LabelBox
  • Using a TurnBox

The tutorials listed above can be completed in any order, however, each tutorial requires the code from this tutorial as its basis.


IGps is an interface representing a generic GPS device. GeoBase has built-in support for these primary GPS devices:

  • A simulated GPS device, using the SimulatedGps class

  • Generic NMEA compatible devices, using the NMEAGps class

To implement your own GPS device it is only necessary to implement your own IGps member. We will briefly discuss (below) the use of the two classes of device described above.

It is not necessary to have an actual GPS device on-hand, the SimulatedGps class will function as a substitute.

The NMEAGps class connects to a COM port, and is designed for interfacing directly with standard NMEA GPS hardware. This class expects exclusive access to the GPS device.

Prior Knowledge

This tutorial assumes basic knowledge of GeoBase routing and the creation of a simple GeoBase application.

The following tutorials may provide useful background reading:

Using SimulatedGps

A SimulatedGps is a simulated GPS unit that follows a predefined set of points at the maximum allowable speed limit. The following code returns a SimulatedGps following a predefined route along a freeway:

private IGps GetGps() {
  /* define a sample route for us to simulate */
  RouteStop start = new RouteStop(new LatLon(33.65856, -117.75528));
  RouteStop end = new RouteStop(new LatLon(33.65006, -117.75523));
  Route route = new Route(start, end);
  LatLon[] points = route.GetDirections().Points;

  /* create and return a SimulatedGps following the route points */
  return new SimulatedGps(points[0], points);
Using NMEAGps

The NMEAGps class interfaces with a standard NMEA GPS device. The following code demonstrates the initialization of a NMEA GPS device connected to the COM1 serial port at a baud rate of 9600. You may need to adjust these properties to suit your GPS device.

private IGps GetGps() {
  /* create and configure the GPS's serial port */
  SerialPort myPort = new SerialPort();
  myPort.PortName = "COM1";
  myPort.BaudRate = 9600;

  /* create NMEA GPS from port, power it up & return */
  IGps myGps = new NMEAGps(myPort);
  return myGps;
Creating the Application

Create a new Visual Studio Project. Add the following controls to the form:

  • A GeoBase map control named mapMain
  • A button named buttonGo

When run your application should appear similar to the screenshot below:

tutorial navigation application

The map can be centered and rotated to match the current location and heading of the GPS device by adding the following UpdateLocation method:

IGps myGps;
RendererList renderList = new RendererList();
private void UpdateLocation(object sender, EventArgs e) {
  renderList.Add(new PushPin(myGps.Position.location));
  mapMain.Center = myGps.Position.location;
  mapMain.Heading = myGps.Position.heading;

  /* invalidating the map causes a redraw */

To make the code simpler and more readable, add the following using directives to the top of the project form.

using Telogis.GeoBase.Routing;
using Telogis.GeoBase.Navigation;
using Telogis.GeoBase;

Add a click event to buttonGo. We will use the click event to initialize our chosen GPS device and start a timer which will update the map using the UpdateLocation() method (above). Ensure that the GetGps() function (see examples above) is implemented to return a suitable GPS device.

private void buttonGo_Click(object sender, EventArgs e) {
  mapMain.Renderer =
  renderList; /* set map to render everything on our list */

  mapMain.Zoom =
  0.5; /* zoom the map close */

  myGps = GetGps(); /* initialize gps */

  /* start a timer that fires every second, calling our eventhandler */
  Timer tim = new Timer();
  tim.Interval = 1000;
  tim.Tick += new EventHandler(UpdateLocation);

Run the application. After clicking the 'Go' button your location will be periodically shown on the map as a PushPin, and the map will rotate to match your direction of travel.

Tip Tip

It is recommended that you create an archive of this project, as it will be modified slightly for each of the following tutorials

The application will appear similar to the screenshot below:

tutorial navigation igps
Next Topic