Example T1263358
Visible to All Users

WinForms Maps - Create a Custom Search Panel Using the Microsoft Azure Maps Search Service

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 the AzureKey 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

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

AzureMapSearch/Form1.cs
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); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.