Click or drag to resize

Getting Directions

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

In the previous topic we added routing functionality to our application. In this topic we will extend the routing capabilities to generate driving directions for a given route.

In addition to adding a new directions method some of the existing methods must be modified to ensure that our application behaves in a logical and consistent manner.

Note Note
We need a Route object to generate directions, so it's important that you completed the previous topic: Creating and Optimizing a Route.
Getting and Displaying Directions

This is a straightforward process and you will notice that the code given here bears many similarities to previous topics.

In the Designer, add a menu item "Get directions" to the right-click context menu that we created in the previous topic. Add a Click event, switch to the Code View and add the following code:

C#
 private void getDirectionsToolStripMenuItem_Click(object sender, EventArgs e) {
    try {
    // directions generation could take a while
    this.Cursor = Cursors.WaitCursor;

    // generate new directions and add them to the renderlist for display
    directions = route.GetDirections();
    renderList.Add(directions);

    // force the map to redraw to show our changes
    mapMain.Invalidate();
  } catch (Exception ex) {
    this.Cursor = Cursors.Default;
    MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  }
     this.Cursor = Cursors.Default;
}
Note Note

It is possible that an exception will be thrown if GeoBase could not generate directions. This could occur if, for example, route stops are on islands not joined by a bridge or ferry route. In this case the exception message is shown in a MessageBox.

End of Tutorial

You should now have a working application that demonstrates some of the built-in capabilities of GeoBase.