Back to Devexpress

Geocode

wpf-17464-controls-and-libraries-map-control-gis-data-geocode.md

latest10.5 KB
Original Source

Geocode

  • Jul 08, 2025
  • 5 minutes to read

The Map control supports Azure Geocode and the OpenStreetMap Geocode services, which provide information associated with the geographic point on a map (address, postcode, etc.) based on a point’s location (latitude and longitude coordinates).

AzureGeocodeDataProvider and OsmGeocodeDataProvider provide the geocoding functionality. The sections below explain how to use them in the map control.

Important

On May 21, 2024, Microsoft announced that Bing Maps for Enterprise and its API will be discontinued. Azure Maps will be a single unified enterprise mapping platform available from Microsoft.

To obtain and display map data from Azure Maps, we implemented the following providers:

For information on how to migrate your app from Bing Maps to Azure Maps, see the following help topic: DevExpress Map Control for WPF: Migrate from Bing Maps to Azure Maps.

If you already have a Bing Maps for Enterprise license, you can keep using the current API. You must transition to the new API by June 30, 2025 (for free/basic licenses) or June 30, 2028 (for enterprise licenses). New licenses will no longer be available after June 30, 2025. Bing Maps will not work with our map controls without a license after that date.

Enable Geocode

Do the following to enable geocoding in the Map control:

The code snippet below shows how to do this.

xaml
<dxm:InformationLayer.DataProvider>
    <dxm:AzureGeocodeDataProvider AzureKey="{Binding Source={StaticResource AzureKey}}"
                                  MaxVisibleResultCount="1"/>
</dxm:InformationLayer.DataProvider>

When the Map control is connected to the Geocode service, you can use the pushpin’s tooltip to obtain information about a geographic point:

  • Click the desired location on a map.

  • Hover the mouse cursor over the pushpin to see its tooltip.

The image below shows how this works for “Kennedyville”.

You can also use the InformationDataProviderBase.MaxVisibleResultCount property to specify how many tooltips can be shown on a map simultaneously.

Use a Custom UI

The map control allows you to obtain additional results (address, name, entity type, etc.) from the Geocode service for a specified location.

Note

Set the InformationDataProviderBase.ProcessMouseEvents property to false if you do not want to generate pushpins when you click on the map.

To start geocoding for a location, call the AzureGeocodeDataProvider.RequestLocationInformation(GeoPoint) or OsmGeocodeDataProvider.RequestLocationInformation method.

For instance, you have a UI that consists of 2 text boxes named “tbLatitude” and “tbLongitude”, and a button named “requestLocation”. To start a search, click the Request Location button. This calls the RequestLocationInformation method.

The results are stored by the RequestResultBase object’s GeocodeRequestResult descendant within the LocationInformationReceived event handler arguments’ LocationInformationReceivedEventArgs.Result.

The results contain the entity type, address, and coordinates associated with the geographic location.

csharp
GeoPoint location = new GeoPoint(40, -120);     
public GeoPoint Location {
    get { return location; }
    set { location = value;} 
}

private void requestLocation_Click(object sender, RoutedEventArgs e) {
    geocodeProvider.RequestLocationInformation(Location, null);
}
vb
Private location_Renamed As New GeoPoint(40, -120)
Public Property Location() As GeoPoint
    Get
        Return location_Renamed
    End Get
    Set(ByVal value As GeoPoint)
        location_Renamed = value
    End Set
End Property

Private Sub requestLocation_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    geocodeProvider.RequestLocationInformation(Location, Nothing)
End Sub

Process Geocode Results

To get the geocode results for a specified location, handle the AzureGeocodeDataProvider.LocationInformationReceived or OsmGeocodeDataProvider.LocationInformationReceived event. The results are stored by the RequestResultBase object’s GeocodeRequestResult descendant within the LocationInformationReceived event handler’s LocationInformationReceivedEventArgs.

The following code snippet shows how to handle the event.

xaml
<dxm:AzureGeocodeDataProvider x:Name="geocodeProvider" ProcessMouseEvents="False"
    AzureKey="{Binding Source={StaticResource YourAzureKey}}" 
    LocationInformationReceived="geocodeProvider_LocationInformationReceived"/>
csharp
private void geocodeProvider_LocationInformationReceived(object sender, LocationInformationReceivedEventArgs e) {
    GeocodeRequestResult result = e.Result;
    StringBuilder resultList = new StringBuilder("");
    resultList.Append(String.Format("Status: {0}\n", result.ResultCode));
    resultList.Append(String.Format("Fault reason: {0}\n", result.FaultReason));
    resultList.Append(String.Format(" ______________________________ \n"));

    if (result.ResultCode != RequestResultCode.Success) {
        tbResults.Text = resultList.ToString();
        return; 
    }

    int resCounter = 1;
    foreach (LocationInformation locations in result.Locations) {
        resultList.Append(String.Format("Request Result {0}:\n", resCounter));
        resultList.Append(String.Format("Display Name: {0}\n", locations.DisplayName));
        resultList.Append(String.Format("Entity Type: {0}\n", locations.EntityType));
        resultList.Append(String.Format("Address: {0}\n", locations.Address));
        resultList.Append(String.Format("Location: {0}\n", locations.Location));
        resultList.Append(String.Format(" ______________________________ \n"));
        resCounter++;
    }

    tbResults.Text = resultList.ToString();
}
vb
Private Sub geocodeProvider_LocationInformationReceived(ByVal sender As Object, ByVal e As LocationInformationReceivedEventArgs)
    Dim result As GeocodeRequestResult = e.Result
    Dim resultList As New StringBuilder("")
    resultList.Append(String.Format("Status: {0}" & ControlChars.Lf, result.ResultCode))
    resultList.Append(String.Format("Fault reason: {0}" & ControlChars.Lf, result.FaultReason))
    resultList.Append(String.Format(" ______________________________" & ControlChars.Lf))

    If result.ResultCode <> RequestResultCode.Success Then
        tbResults.Text = resultList.ToString()
        Return
    End If

    Dim resCounter As Integer = 1
    For Each locations As LocationInformation In result.Locations
        resultList.Append(String.Format("Request Result {0}:" & ControlChars.Lf, resCounter))
        resultList.Append(String.Format("Display Name: {0}" & ControlChars.Lf, locations.DisplayName))
        resultList.Append(String.Format("Entity Type: {0}" & ControlChars.Lf, locations.EntityType))
        resultList.Append(String.Format("Address: {0}" & ControlChars.Lf, locations.Address))
        resultList.Append(String.Format("Location: {0}" & ControlChars.Lf, locations.Location))
        resultList.Append(String.Format(" ______________________________" & ControlChars.Lf))
        resCounter += 1
    Next locations

    tbResults.Text = resultList.ToString()
End Sub

The results for Latitude - “41.27” and Longitude - “-96.05” are shown in the image below.

See Also

Search

Routing

WPF Map Control: Examples

DevExpress Map Control for WPF: Migrate from Bing Maps to Azure Maps