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:
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:
- Azure
Map Data Provider - Azure
Search Data Provider - Azure
Route Data Provider - Azure
Geocode Data Provider - Azure
Traffic Incident Data Provider - Azure
Route Isochrone Data Provider
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.
#Enable Search
Do the following to enable search in the Map control:
Create an information layer and add it to the map.
The information layer provides vector elements that represent GIS data obtained from the Search service in the Map control. Refer to the Layers guide to learn more about layers.
- Create the AzureSearchDataProvider or OsmSearchDataProvider instance and assign it to the InformationLayer.DataProvider property.
- Specify the Azure Maps key for the Azure Data Provider using the AzureMapDataProviderBase.AzureKey property.
The code snippet below shows how to do this.
<!-- -->
<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 Map
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:
private void Search_Click(object sender, RoutedEventArgs e) {
searchDataProvider.Search(teKeywords.Text);
}
#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.
<dxm:AzureSearchDataProvider x:Name="searchDataProvider"
AzureKey="{Binding Source={StaticResource azureMapsKey}}"
SearchCompleted="OnSearchCompleted"
LayerItemsGenerating="OnLayerItemsGenerating"/>
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();
}
The search results for the “New York” keywords are shown in the image below.