Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

  • 2 minutes to read

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

DevExpress MapControl for WPF - An address found using AzureGeocodeProvider based on a geo point

<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>
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);
        }
    }
}
See Also