Skip to main content

Search

  • 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:

MapControl_Searching

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

Important

Due to Bing canceling the SOAP service on July 30, 2017, the Map Control’s Bing Search provider does not work correctly in version 16.1 and earlier.

Enabling Search

Do the following to enable search in the Map control:

The code snippet below shows how to do this.

<!-- -->
<dxm:MapControl>
    <!-- Image Tile Provider customization here.-->
    <dxm:InformationLayer>
        <dxm:InformationLayer.DataProvider>
            <dxm:BingSearchDataProvider BingKey="YOUR_BING_MAPS_KEY"/>
        </dxm:InformationLayer.DataProvider>
    </dxm:InformationLayer>
</dxm:MapControl>
<!-- -->

You can also specify the request result count obtained from the service using the BingSearchDataProvider.SearchOptions property.

<!-- -->
<dxm:BingSearchDataProvider BingKey="YOUR_BING_MAPS_KEY">
    <dxm:BingSearchDataProvider.SearchOptions>
        <dxm:BingSearchOptions ResultsCount="5"/>
    </dxm:BingSearchDataProvider.SearchOptions>
</dxm:BingSearchDataProvider>
<!-- -->

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 BingSearchDataProvider.Search or OsmSearchDataProvider.Search method.

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

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 BingSearchDataProvider.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

<dxm:BingSearchDataProvider x:Name="searchDataProvider"
                            BingKey="{Binding Source={StaticResource bingMapsKey}}"
                            SearchCompleted="OnSearchCompleted"
                            LayerItemsGenerating="OnLayerItemsGenerating"/>

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

CustomSearchResult

See Also