Back to Devexpress

Search

wpf-17463-controls-and-libraries-map-control-gis-data-search.md

latest9.2 KB
Original Source

Search

  • Jul 08, 2025
  • 4 minutes to read

The Map Control library includes several classes that return search result from geo-search services:

When the search is enabled, you can type a search criterion in the built-in Search Panel and view the results on the map and in the search panel’s result list:

Alternatively, Search Providers’ API allows you to implement a custom UI to send a search request and display search results.

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.

Do the following to enable search in the Map control:

The code snippet below shows how to do this.

xaml
<!-- -->
<dxm:MapControl>
    <!-- Image Tile Provider customization here.-->
    <dxm:InformationLayer>
        <dxm:InformationLayer.DataProvider>
            <dxm:AzureSearchDataProvider AzureKey="YOUR_AZURE_MAPS_KEY"/>
        </dxm:InformationLayer.DataProvider>
    </dxm:InformationLayer>
</dxm:MapControl>
<!-- -->

When the Map Control contains an Information Layer that provides Search data, the Map control automatically invokes its built-in search panel (the MapControl.ShowSearchPanel is set to true by default). Refer to the Search Panel topic to learn more about the built-in Search panel.

Using a Custom UI

The Map control provides a search functionality with additional parameters like a country region or postal code. Using this approach, you can build a custom search panel to get additional search results from the Search services.

Note

Set the MapControl.ShowSearchPanel property to false to disable the default Search panel when using this approach.

To start searching for a location, call the AzureSearchDataProvider.Search or OsmSearchDataProvider.Search method. Use the maxResults parameter to specify the number of results that can be obtained by a search request.

For example, an Application’s UI contains a text edit named “teKeywords” and a button named “btnSearch”. To start a search, click the Search button which calls the following Search method overload:

View Example

csharp
private void Search_Click(object sender, RoutedEventArgs e) {
    searchDataProvider.Search(teKeywords.Text);
}
vb
Private Sub Search_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    searchDataProvider.Search(teKeywords.Text)
End Sub

Search Results

To get the search results, handle the AzureSearchDataProvider.SearchCompleted or OsmSearchDataProvider.SearchCompleted event.

The SearchCompleted event handler arguments’ SearchCompletedEventArgs.RequestResult provides the SearchRequestResult descendant class instance to store Search results.

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

View Example

xaml
<dxm:AzureSearchDataProvider x:Name="searchDataProvider"
                            AzureKey="{Binding Source={StaticResource azureMapsKey}}"
                            SearchCompleted="OnSearchCompleted"
                            LayerItemsGenerating="OnLayerItemsGenerating"/>
csharp
private void OnSearchCompleted(object sender, AzureSearchCompletedEventArgs e) {
    if(e.Cancelled) return;
    if(e.RequestResult.ResultCode != RequestResultCode.Success) {
        teResult.Text = "The Azure Search service does not work for this location.";
        return;
    }

    StringBuilder resultList = new StringBuilder("");
    int resCounter = 1;
    foreach(LocationInformation resultInfo in e.RequestResult.SearchResults) {
        resultList.Append(String.Format("Result {0}: \r\n", resCounter));
        resultList.Append(String.Format("Name: {0}\r\n", resultInfo.DisplayName));
        resultList.Append(String.Format("Address: {0}\r\n", resultInfo.Address.FormattedAddress));
        resultList.Append(String.Format("Geographic coordinates: {0}\r\n", resultInfo.Location));
        resultList.Append(String.Format(" ______________________________ \r\n"));
        resCounter++;
    }
    teResult.Text = resultList.ToString();
}
vb
Private Sub OnSearchCompleted(ByVal sender As Object, ByVal e As AzureSearchCompletedEventArgs)
    If e.Cancelled Then
        Return
    End If
    If e.RequestResult.ResultCode <> RequestResultCode.Success Then
        teResult.Text = "The Azure Search service does not work for this location."
        Return
    End If

    Dim resultList As New StringBuilder("")
    Dim resCounter As Integer = 1
    For Each resultInfo As LocationInformation In e.RequestResult.SearchResults
        resultList.Append(String.Format("Result {0}: " & ControlChars.CrLf, resCounter))
        resultList.Append(String.Format("Name: {0}" & ControlChars.CrLf, resultInfo.DisplayName))
        resultList.Append(String.Format("Address: {0}" & ControlChars.CrLf, resultInfo.Address.FormattedAddress))
        resultList.Append(String.Format("Geographic coordinates: {0}" & ControlChars.CrLf, resultInfo.Location))
        resultList.Append(String.Format(" ______________________________" & ControlChars.CrLf))
        resCounter += 1
    Next resultInfo
    teResult.Text = resultList.ToString()
End Sub

The search results for the “New York” keywords are shown in the image below.

See Also

WPF Map Control: Examples

Geocode

Routing

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