Click or drag to resize

Using a TurnBox

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

This section describes the use of a TurnBox to display turn information above a map. A TurnBox will draw the next turn that the navigator (driver) must make in order to navigate to the desired destination.

Note Note

We will modify the sample application (created in The IGps Interface tutorial) to use a TurnBox to display the upcoming turn event.

Prior Knowledge

This tutorial assumes basic knowledge of:

Using a TurnBox

TurnBox implements the IMapRenderer interface, so to draw a TurnBox we can add the TurnBox to our map's RendererList. Add the following code to the form declarations (beneath the renderList):

TurnBox tBox = new TurnBox();

Remove the following line from your project.

IGps myGps;

Next, remove the GetGps() method in its entirety. This won't be needed for this example as we will create a new SimulatedGps in the buttonGo click event for our Navigator.

Add the following code to the declarations, beneath our TurnBox constructor:

private Navigator nav;

String LangsPath = Settings.GeoBasePath("langs");
readonly private LatLon StartLocation = new LatLon(33.65856, -117.75528);
readonly private LatLon DestinationLocation = new LatLon(33.65006, -117.75523);

Modify your UpdateLocation() method to match the code segment below. This ensures that the map is regularly updated with our current Navigator position and heading.

 /* update current location of Navigator */
renderList.Add(new PushPin(nav.Gps.Position.location));
mapMain.Center = nav.Gps.Position.location;
mapMain.Heading = nav.Gps.Position.heading;

/* invalidating the map causes a redraw */

A TurnBox will be hidden from view if its CurrentEvent property is set to null.

We will show the TurnBox using a NotificationDelegate that will fire 100 meters before a turn event.

We will hide the TurnBox after each turn by using a second NotificationDelegate, firing on the Navigator object's AfterTurnDistanceNotification event.

Tip Tip

The Navigator object's Destination property allows the Navigator to correctly determine the turn direction.

You will need to add two methods to your code:

  • ClearTurnBox() will reset the CurrentEvent of the TurnBox to null. This means that the TurnBox will be hidden from view.
  • SetTurnBox() sets the TurnBox object's CurrentEvent property to the upcoming NavigationEvent (received as a parameter of the NotificationDelegate).
private void ClearTurnBox(object sender, NavigationEvent e) {
  tBox.CurrentEvent = null;

private void SetTurnBox(object sender, NavigationEvent e) {
  tBox.CurrentEvent = e;

Copy following lines of code over your buttonGo click event contents. This code in this segment will:

mapMain.Renderer =
 renderList; /* set map to render everything on our list */

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

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

 /* set up Navigator */
 nav = new Navigator(new SimulatedGps(StartLocation), LangsPath, System.Globalization.CultureInfo.CurrentCulture);
 nav.Destination = new RouteStop(DestinationLocation);

 /* set up Navigator's notifications */
 NotificationDelegate setDel = new NotificationDelegate(SetTurnBox);
 nav.AddNotification(new BeforeTurnDistanceNotification(100, 20, DistanceUnit.METERS, setDel));
 NotificationDelegate clrDel = new NotificationDelegate(ClearTurnBox);
 nav.AddNotification(new AfterTurnDistanceNotification(25, DistanceUnit.METERS, clrDel));

Next, beneath this (still within the buttonGo_Click event), add the Turn box and the Navigator to the map's RendererList:


Add the following line of code to your UpdateLocation() method to ensure that the Navigator is updated with its current location.

nav.AddPoint(); /* update current location of Navigator */

Run the sample application. After you click buttonGo your application will, before a turn, draw a TurnBox showing the direction required to navigate towards the Navigator object's set Destination property. The TurnBox will be cleared after a turn has been made.

tutorial navigation turnbox
Next Topic