Click or drag to resize

Using an XmlWaveAnnouncer

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

An XmlWaveAnnouncer may be used to audibly alert the user to upcoming navigation events. An XmlWaveAnnouncer is particularly useful in circumstances where it is inconvenient for the user to rely on visual cues for navigation.

In this section of the tutorial we will use an XmlWaveAnnouncer to alert the user to upcoming turn events, using a BeforeTurnTimeNotification.

Prior Knowledge

This tutorial assumes basic knowledge of:

Note Note

This tutorial builds on, or modifies the code written in The IGps Interface.

Using an XmlWaveAnnouncer

The following method retrieves the current and pending NavigationEvents from the Navigator and passes the events to the XmlWaveAnnouncer. If the pending event will occur soon after the current event then both will be announced simultaneously.

In the next step we will create a Navigator and set the Navigator to call this Announce() method before every turn.

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

C#
using Telogis.GeoBase.Navigation.Announcements;

Copy the following code below the buttonGo_Click method.

C#
WaveAnnouncer wa = new XmlWaveAnnouncer();

private void Announce(object sender, EventArgs e) {
  /* get upcoming navigation events to announce */
  NavigationEvent current = nav.CurrentNavigationEvent;
  NavigationEvent pending = nav.NextNavigationEvent;
  wa.Units = UnitSystem.ImperialYards;
  wa.SayMovement(current, pending);
}

Remove the following line from your project.

C#
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.

Modify your buttonGo click event code to match the code segment below. This code segment will:

  • create a new Navigator using a SimulatedGps with a set Destination
  • create and add a BeforeTurnTimeNotification to the Navigator. This notification will call the Announce() method 10-30 seconds before a turn
C#
private Navigator nav;

readonly private 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);

private void buttonGo_Click(object sender, EventArgs e){
    mapMain.Zoom = 0.5; /* zoom the map close */

    /* set up Navigator */
    nav = new Navigator(new SimulatedGps(StartLocation), LangsPath, System.Globalization.CultureInfo.CurrentCulture);
    nav.Destination = new RouteStop(DestinationLocation);
    nav.AddNotification(new BeforeTurnTimeNotification(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(10), Announce));

    /* set items to render */
    mapMain.Renderer = renderList;
    renderList.Add(nav);

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

Copy the following code snippet over your UpdateLocation() method's existing content. This ensures that the Navigator object is regularly updated with our current position.

C#
/* 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;

mapMain.Invalidate();
/* invalidating the map causes a redraw */

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

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

Run the sample application. After you click buttonGo your application will start to display the current location. Before a turn the event will be announced by the XmlWaveAnnouncer.

Note Note

A series of 'beeps' is an indication that GeoBase was unable to find the langs\en-US directory or associated sound files or both. In this case, verify your GeoBase installation or pass the path to the langs directory when you construct the XmlWaveAnnouncer.

See the documentation for the XmlWaveAnnouncer constructor for more information.

Next Topic