Skip to main content

Elevation

  • 3 minutes to read

This document explains how to provide a Map control with the capability to obtain elevation information of a location on a map.

A map callout shows elevation for a geo point

The document consists of the following sections.

Overview

The Map control supports the Microsoft Bing Elevation service, allowing you to embed elevation requesting functionality to your map. When this feature is enabled, you can click on the map and obtain elevation information from the service.

The search functionality in the map control is performed by the Bing Search data provider. This provider is represented by the BingElevationDataProvider object. The section below explains how to use the BingElevationDataProvider in the map control.

Enabling Elevation Requesting

To enable elevation requesting in the Map control, do the following.

The code snippet below shows how this can be done.

// Create a new elevation data provider.
BingElevationDataProvider dataProvider = new BingElevationDataProvider {
    BingKey = yourBingKey,
    ProcessMouseEvents = true
};
informationLayer.DataProvider = dataProvider;
// Process result obtaining.
dataProvider.ElevationsCalculated += OnElevationsCalculated;

Using a Custom UI

The Map control provides the elevation request functionality for several points. Using this approach, you can build a custom request panel to get additional results from the Microsoft Bing Elevation service.

To send an elevation request, call the BingElevationDataProvider.RequestPointElevation or BingElevationDataProvider.RequestPointsElevations method.

For instance, you have a UI that consists of 2 text boxes named “tbLatitude”, “tbLongitude”, and a button named “Request Elevation”. To send a request, click the button. This calls the RequestPointElevation method.

private void OnClick(object sender, EventArgs e) {    
    elevationProvider.RequestPointsElevations(new GeoPoint { 
        Latitude = Convert.ToDouble(tbLatitude.Text), 
        Longitude = Convert.ToDouble(tbLongitude.Text)
    });
} 

Processing Elevation Request Result

To get the results for the request, handle the BingElevationDataProvider.ElevationsCalculated event, as shown below.

private void OnElevationsCalculated(object sender, ElevationsCalculatedEventArgs e) {
    if(e.Cancelled == true || e.Error != null) return;
    if(e.Result.ResultCode != RequestResultCode.Success) return;

    informationLayer.Data.Items.Clear();
    // foreach requested location create a new callout with elevation value.
    foreach (ElevationInformation elevationResult in e.Result.Locations) {
        informationLayer.Data.Items.Add(new MapCallout {
            Location = elevationResult.Location,
            Text = String.Format("Elevation: {0}m.", elevationResult)
        });
    }
}

In the code above, the ElevationsCalculatedEventArgs.Result property is used to obtain the request results. The ElevationRequestResult.Locations property stores the elevation data for the points that had be sent in the request.