Click or drag to resize

Using a LabelBox

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

This section of the tutorial demonstrates the use of a LabelBox to display information above a map.

Note Note

We will modify the sample application created in the tutorial The IGps Interface to use a LabelBox to display the current heading, speed and GPS fix.

Using the LabelBox

The LabelBox class, like the PushPin in the previous tutorial, implements IMapRenderer. To draw a LabelBox we add the LabelBox to our RendererList.

The LabelBox has a parameterless constructor. Add the following snippet to your code such that the created LabelBox is global.

LabelBox lBox = new LabelBox();

The following code snippet will initialize the LabelBox to be positioned in the top right-hand corner of the map at a size of 150 x 150 pixels. Add this code snippet to your buttonGo click event.

/* setup labelbox - 150x100px, top RH corner */
lBox.Size = new System.Drawing.Size(150, 100);
lBox.Top = mapMain.Top;
lBox.Left = mapMain.Right - lBox.Width - 20;

/* it won't be drawn until it's on the renderlist */

Modify your UpdateLocation() method to match the code segment below. This code segment is almost identical to that in the previous tutorial, with the addition of code to:

  • retrieve the current heading, speed and number of satellites in the GPS fix
  • set the major and minor text in the LabelBox to the appropriate attributes
private void UpdateLocation(object sender, EventArgs e) {
  /* get the current heading ('N', 'NE' etc), speed (mph) and number of satellites in GPS fix */
  string headAbbrev = Position.HeadingString(myGps.Position.heading);
  double mphSpeed = MathUtil.ConvertUnits(myGps.Position.speed, myGps.Position.units, SpeedUnit.MilesPerHour);
  int sats = myGps.Position.quality.NumSats;

  /* update labelbox, with heading & speed as major text, fix as minor text */
  lBox.MajorText = string.Format("Traveling {0}\nSpeed: {1:##} mph", headAbbrev, mphSpeed);
  lBox.MinorText = string.Format("Fix from {0} satellites", sats);

  /* add pushpin (at current gps location) */
  renderList.Add(new PushPin(myGps.Position.location));

  /* update the map center and heading */
  mapMain.Center = myGps.Position.location;
  mapMain.Heading = myGps.Position.heading;
  mapMain.Invalidate(); /* invalidating the map causes a redraw */

Run the sample application. After you click buttonGo your application will appear similar to the screenshot below.

tutorial navigation labelbox
Next Topic