Search
- 4 minutes to read
This document explains how to provide a Map control with the capability to search for a location on a map and get additional search results.
The document consists of the following sections.
#Overview
The Map control supports the popular Microsoft Bing Search service, allowing you to embed search functionality in your application. When this feature is enabled, you can type search criteria in the Search Panel (or use a custom UI), implement a request, and view the results in both the map and the search panel.
NOTE
The search feature should interact with one of the map data providers (Bing Maps or Open
The search functionality in the map control is performed by the Bing Search data provider. This provider is represented by the BingSearchDataProvider object. The section below explains how to use the BingSearchDataProvider in the map control.
#Enabling Search
To enable search in the Map control, do the following.
Create an information layer and add it to the map.
The information layer is used to present GIS elements above the map. For more information, see Layers.
- Create an instance of the BingSearchDataProvider and assign it to the InformationLayer.DataProvider property.
Specify the Bing Maps key via the BingSearchDataProvider.BingKey property.
NOTE
If you run the application, and see a window with the following error message: ”The specified Bing Maps key is invalid. To create a developer account, refer to http://www.
microsoft. , refer to the following tutorial: How to: Get a Bing Maps Key.com/maps/developers”
The code snippet below shows how this can be done.
<!-- -->
<dxm:MapControl Name="mapControl1">
<!-- -->
<dxm:InformationLayer>
<dxm:InformationLayer.DataProvider>
<dxm:BingSearchDataProvider BingKey="YOUR_BING_MAPS_KEY"/>
</dxm:InformationLayer.DataProvider>
</dxm:InformationLayer>
</dxm:MapControl>
<!-- -->
In addition, you can customize the distance unit, the search radius and other search options.
<!-- -->
<dxm:BingSearchDataProvider BingKey="YOUR_BING_MAPS_KEY">
<dxm:BingSearchDataProvider.SearchOptions>
<dxm:BingSearchOptions AutocorrectQuery="False" DistanceUnit="Mile"
ResultsCount="5" SearchRadius="200" />
</dxm:BingSearchDataProvider.SearchOptions>
</dxm:BingSearchDataProvider>
<!-- -->
After the search feature is enabled, the Map control's built-in search panel is automatically invoked (the BingSearchDataProvider.ShowSearchPanel is set to true by default). To learn more about the built-in Search panel, see the Search Panel topic.
#Using a Custom UI
The Map control provides search functionality for additional parameters (location, keywords, geographical point coordinates, etc.). Using this approach, you can build a custom search panel to get additional search results from the Microsoft Bing Search service.
NOTE
The built-in Search panel is not used for this approach, so make sure that the Bing
To start searching for a location, keywords and other additional parameters, call the BingSearchDataProvider.Search method.
NOTE
There are 6 overloads for the Search method, depending on your search criteria.
For instance, you have a UI that consists of 5 text boxes named "tbKeywords", "tbLocation", "tbLatitude", "tbLongitude", "tbStartingIndex" and a button named "bSearch". To start a search, click the Search button. This calls the following overload of the Search method.
This example shows how to use the BingSearchDataProvider.Search method.
#Search Results
To get the results of the executed search, handle the BingSearchDataProvider.SearchCompleted event, as shown below.
Search results are held by the RequestResultBase object's SearchRequestResult descendant within the BingSearchCompletedEventArgs of the SearchCompleted event handler.
The results contain a display name, an address, and the geographic coordinates (latitude and longitude) associated with the search location.
The search results for Keywords ("coffee shop") and Location ("California") are shown in the image below.
In addition, you can obtain the search region in which the results are located via the SearchRequestResult.SearchRegion property, and return the results of a search for alternate regions using the SearchRequestResult.AlternateSearchRegions property.
#Examples
The following examples demonstrate how to use the search feature in the Map control.