Back to Devexpress

AzureGeocodeDataProvider Class

wpf-devexpress-dot-xpf-dot-map-7ecc5530.md

latest7.6 KB
Original Source

AzureGeocodeDataProvider Class

Allows you to obtain geo data from the Azure Maps Geocode service.

Namespace : DevExpress.Xpf.Map

Assembly : DevExpress.Xpf.Map.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public class AzureGeocodeDataProvider :
    AzureMapDataProviderBase,
    IMouseClickRequestSender
vb
Public Class AzureGeocodeDataProvider
    Inherits AzureMapDataProviderBase
    Implements IMouseClickRequestSender

Remarks

The map control allows you to use the Azure Maps Search service to search for a full or partial address and return the longitude and latitude coordinates of the address. This process is called geocoding. The ability to geocode in a country/region depends on the availability of road data and the precision of the geocoding service. For more information about Azure Maps’ geocoding capabilities by country or region, see Geocoding coverage.

The AzureGeocodeDataProvider implements the Azure Maps Geocode service. Assign this object to the InformationLayer.DataProvider property to enable the service and allow users to obtain information about a point on a map.

Azure Maps services support JSON response formats. Install the System.Text.Json package in projects that target .NET Framework to parse the Azure server response and display information on a DevExpress Map control.

Call the RequestLocationInformation method overloads to obtain information about the specified location.

To get geocode results, handle the LocationInformationReceived event. The e.Result argument returns a GeocodeRequestResult descendant that stores geocode results.

If you wish to specify the number of requested results displayed, use the MaxVisibleResultCount property.

For more information on how to use geocoding services, refer to the following help topic: Geocode.

Example

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

Implements

ISupportWebRequest

IMouseClickRequestSender

Inheritance

Object DispatcherObject DependencyObject Freezable MapDependencyObject InformationDataProviderBase WebInformationDataProvider<DevExpress.Map.Native.JsonProvidedEventArgs> AzureMapDataProviderBase AzureGeocodeDataProvider

See Also

AzureGeocodeDataProvider Members

DevExpress.Xpf.Map Namespace