Skip to main content
All docs
V25.1
  • AzureSearchDataProvider Class

    Contains settings that are used by requests to the Azure Maps Search service.

    Namespace: DevExpress.XtraMap

    Assembly: DevExpress.XtraMap.v25.1.dll

    NuGet Package: DevExpress.Win.Map

    Declaration

    public class AzureSearchDataProvider :
        AzureMapDataProviderBase,
        ISearchPanelRequestSender

    Remarks

    AzureSearchDataProvider implements the Azure Maps Search service. Assign such an object to the InformationLayer.DataProvider property to display the search panel and allow users to search for a specific place on a map. To hide the search panel, set the MapSearchPanelOptions.Visible property to false.

    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.

    Search at Runtime

    Call one of the AzureSearchDataProvider.Search overloads to search for locations that correspond to the specified attributes. The maxResults parameter of the Search method overloads allows you to specify the number of results that can be obtained by a search request.

    The following example searches for locations that correspond to the specified AzureAddress:

    using DevExpress.XtraMap;
    // ...
    const string azureKey = "your key";
    // ...
    private void Form1_Load(object sender, EventArgs e) {
        // Create a map control.
        MapControl map = new MapControl();
        // Specify the map position on the form.           
        map.Dock = DockStyle.Fill;
        // Create a layer.
        ImageLayer layer1 = new ImageLayer();
        layer1.DataProvider = new AzureMapDataProvider() {
            AzureKey = azureKey,
            // Set Imagery tileset to display a satellite or aerial imagery on a layer.
            Tileset = AzureTileset.Imagery,
        };
        // Create a layer.
        ImageLayer layer2 = new ImageLayer();
        layer2.DataProvider = new AzureMapDataProvider(){
            AzureKey = azureKey,
            // Set BaseLabelsRoad tileset to display boundaries and label data in the Azure Map style on a layer.
            Tileset = AzureTileset.BaseLabelsRoad,
        };
        // Connect to Azure Maps Search service.
        AzureSearchDataProvider azureSearchProvider = new AzureSearchDataProvider() {
            AzureKey = azureKey,
        };
        // Specify the address info.
        azureSearchProvider.Search(new AzureAddress() {
            AddressLine = "15127 NE 24th St",
            CountryRegion = "United States",
            AdminDistricts = new string[,] { { "WA" } , {"King County"} }, 
            Locality = "Redmond",
            PostalCode = "98052"
        }, 5);
        // Create a layer.
        InformationLayer informationLayer = new InformationLayer();
        informationLayer.DataProvider = azureSearchProvider;
        // Zoom the map to fit the search result.
        informationLayer.DataRequestCompleted += OnDataRequestCompleted;
        void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
            map.ZoomToFitLayerItems(0.4);
        }
        // Specify the map zoom level and center point. 
        map.ZoomLevel = 3;
        map.CenterPoint = new GeoPoint(40, -100);
        // Add the created layers to the collection.
        map.Layers.AddRange(new LayerBase[] {
            layer1, layer2, informationLayer});
        // Hide the Search Panel.
        map.SearchPanelOptions.Visible = false;
        // Add the map control to the window.
        this.Controls.Add(map);
    }
    

    Obtain Search Results

    To get search results, handle the AzureSearchDataProvider.SearchCompleted event. The SearchCompletedEventArgs.RequestResult returns a SearchRequestResult descendant that stores search results.

    The results contain a display name, address, and the geographic coordinates (latitude and longitude) associated with the search location:

    See Also