Back to Devexpress

How to: Get Information About a Geographical Point Using the Azure Geocode Service

wpf-12312-controls-and-libraries-map-control-examples-gis-data-geocoding-how-to-get-information-about-a-geographical-point-using-the-bing-geocode-service.md

latest4.2 KB
Original Source

How to: Get Information About a Geographical Point Using the Azure Geocode Service

  • Jun 19, 2025
  • 2 minutes to read

The following example obtains the location information such as location address based on geo point coordinates:

xaml
<Window xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map" ...>
    <Window.Resources>
        <sys:String x:Key="azureKey">
            Your AzureMaps key here.
        </sys:String>
    </Window.Resources>
    <Grid>
        <dxm:MapControl Loaded="MapControl_Loaded" x:Name="mapControl" ToolTipEnabled="True" ShowSearchPanel="False">
            <dxm:ImageLayer>
                <dxm:AzureMapDataProvider AzureKey="{StaticResource azureKey}" Tileset="BaseRoad"/>
            </dxm:ImageLayer>
            <dxm:InformationLayer x:Name="infoLayer">
                <dxm:AzureGeocodeDataProvider x:Name="geocodeProvider" AzureKey="{StaticResource azureKey}"   
                                            LocationInformationReceived="geocodeProvider_LocationInformationReceived"
                                            MaxVisibleResultCount="1" 
                                            ProcessMouseEvents="False"
                                            GenerateLayerItems="False"/>
            </dxm:InformationLayer>
        </dxm:MapControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Map;
using System.Windows;

namespace WpfMapExample {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
        private void MapControl_Loaded(object sender, RoutedEventArgs e) {
            geocodeProvider.RequestLocationInformation(new GeoPoint(40.730610, -73.935242));
        }
        // The following code shows the obtained location information in a pushpin tooltip:
        private void geocodeProvider_LocationInformationReceived(object sender, LocationInformationReceivedEventArgs e) {
            LocationInformation info = e.Result.Locations[0];
            MapPushpin mapPushpin = new MapPushpin { Location = info.Location };
            mapPushpin.ToolTipPattern = info.DisplayName;
            VectorLayer vectorLayer = new VectorLayer();
            MapItemStorage mapItemStorage = new MapItemStorage();
            mapItemStorage.Items.Add(mapPushpin);
            vectorLayer.Data = mapItemStorage;
            mapControl.Layers.Add(vectorLayer);
            mapControl.ZoomToFit(vectorLayer.Data.DisplayItems, 0.4);
        }
    }
}
vb
Imports DevExpress.Xpf.Map
Imports System.Windows

Namespace WpfMapExample
    Public Partial Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub MapControl_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            geocodeProvider.RequestLocationInformation(New GeoPoint(40.730610, -73.935242))
        End Sub

        Private Sub geocodeProvider_LocationInformationReceived(ByVal sender As Object, ByVal e As LocationInformationReceivedEventArgs)
            Dim info As LocationInformation = e.Result.Locations(0)
            Dim mapPushpin As MapPushpin = New MapPushpin With {
                .Location = info.Location
            }
            mapPushpin.ToolTipPattern = info.DisplayName
            Dim vectorLayer As VectorLayer = New VectorLayer()
            Dim mapItemStorage As MapItemStorage = New MapItemStorage()
            mapItemStorage.Items.Add(mapPushpin)
            vectorLayer.Data = mapItemStorage
            mapControl.Layers.Add(vectorLayer)
            mapControl.ZoomToFit(vectorLayer.Data.DisplayItems, 0.4)
        End Sub
    End Class
End Namespace

See Also

How to: Connect a Map Control to the Bing Geocode Service

How to: Create a Custom Geocode Panel