This example uses Microsoft’s Azure Maps Search Service to search for and obtain information on a specific map location.
NOTE:
To incorporate this solution within your DevExpress-powered app, you need an Azure Maps service key. Replace theAzureKey
property value with your subscription key to connect to Azure Maps.
Implementation Details
The original search panel is hidden. The DevExpress TextEdit
UI element is used to specify a search keyword. The “Search for Location” button initiates the search request. To obtain search results, our AzureSearchDataProvider.SearchCompleted
event is raised. The SearchCompletedEventArgs.RequestResult
method returns a SearchRequestResult
descendant (used to store search results). Results displayed within the DevExpress MemoEdit
element include display name, address, and geographic coordinates (latitude and longitude) for a given search location:
Output:
Files to Look At
Documentation
More Examples
- WinForms Maps - Obtain Information about a Geographical Point Using the Microsoft Azure Maps Geocode Service
- WinForms Maps - Use the Azure Maps Route Service to Calculate Routes between GeoPoints on a Map Surface
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using DevExpress.XtraMap;
using DevExpress.XtraPrinting.Native;
using System.Text;
namespace AzureMapSearch {
public partial class Form1 : Form {
const string azureKey = "your key";
AzureSearchDataProvider azureSearchProvider;
public Form1() {
InitializeComponent();
imageLayer1.DataProvider = new AzureMapDataProvider() {
AzureKey = azureKey,
Tileset = AzureTileset.Imagery
};
imageLayer2.DataProvider = new AzureMapDataProvider(){
AzureKey = azureKey,
Tileset = AzureTileset.BaseLabelsRoad,
};
azureSearchProvider = new AzureSearchDataProvider(){
AzureKey = azureKey,
};
informationLayer1.DataProvider = azureSearchProvider;
informationLayer1.DataRequestCompleted += OnDataRequestCompleted;
azureSearchProvider.SearchCompleted += new AzureSearchCompletedEventHandler(OnSearchCompleted);
mapControl1.SearchPanelOptions.Visible = false;
}
void OnDataRequestCompleted(object sender, RequestCompletedEventArgs e) {
mapControl1.ZoomToFitLayerItems(0.4);
}
void OnSearchCompleted(object sender, AzureSearchCompletedEventArgs e) {
if (e.Cancelled) return;
if (e.RequestResult.ResultCode != RequestResultCode.Success) {
memoEdit1.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("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++;
}
memoEdit1.Text = resultList.ToString();
}
private void simpleButton1_Click(object sender, EventArgs e) {
azureSearchProvider.Search(textEdit1.Text, maxResults: 2);
}
}
}