Back to Devexpress

AzureSearchDataProvider.SearchCompleted Event

windowsforms-devexpress-dot-xtramap-dot-azuresearchdataprovider-e3ba585b.md

latest6.3 KB
Original Source

AzureSearchDataProvider.SearchCompleted Event

Occurs when a search operation has been completed.

Namespace : DevExpress.XtraMap

Assembly : DevExpress.XtraMap.v25.2.dll

NuGet Package : DevExpress.Win.Map

Declaration

csharp
public event AzureSearchCompletedEventHandler SearchCompleted
vb
Public Event SearchCompleted As AzureSearchCompletedEventHandler

Event Data

The SearchCompleted event's data class is AzureSearchCompletedEventArgs. The following properties provide information specific to this event:

PropertyDescription
CancelledGets a value indicating whether an asynchronous operation has been canceled. Inherited from AsyncCompletedEventArgs.
ErrorGets a value indicating which error occurred during an asynchronous operation. Inherited from AsyncCompletedEventArgs.
RequestResultReturns the result of the search request. Inherited from SearchCompletedEventArgs.
UserStateGets the unique identifier for the asynchronous task. Inherited from AsyncCompletedEventArgs.

The event data class exposes the following methods:

MethodDescription
RaiseExceptionIfNecessary()Raises a user-supplied exception if an asynchronous operation failed. Inherited from AsyncCompletedEventArgs.

Remarks

To obtain search results for received GIS data, do the following:

  1. Handle the SearchCompleted event.
  2. In the event handler, read the e.RequestResult.SearchResults to obtain an array of LocationInformation objects.

The following image illustrates the result:

csharp
using DevExpress.XtraMap;
// ...
const string azureKey = "your key";
// ...
AzureSearchDataProvider azureSearchProvider = new AzureSearchDataProvider() {
    AzureKey = azureKey,
};
azureSearchProvider.Search("Redmond 15127 NE 24th St");

azureSearchProvider.SearchCompleted += new AzureSearchCompletedEventHandler(OnSearchCompleted);
void OnSearchCompleted(object sender, AzureSearchCompletedEventArgs e) {
    if (e.Cancelled) return;
    if (e.RequestResult.ResultCode != RequestResultCode.Success) {
        MessageBox.Show("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++;
    }
    MessageBox.Show(resultList.ToString());
}
InformationLayer informationLayer = new InformationLayer();
informationLayer.DataProvider = azureSearchProvider;
map.Layers.Add(informationLayer);
vb
Imports DevExpress.XtraMap
' ...
Private Const azureKey As String = "your key"
' ...
Dim azureSearchProvider As New AzureSearchDataProvider() With {.AzureKey = azureKey}
azureSearchProvider.Search("Redmond 15127 NE 24th St")

Private azureSearchProvider.SearchCompleted += New AzureSearchCompletedEventHandler(AddressOf OnSearchCompleted)
Private Sub OnSearchCompleted(ByVal sender As Object, ByVal e As AzureSearchCompletedEventArgs)
    If e.Cancelled Then
        Return
    End If
    If e.RequestResult.ResultCode <> RequestResultCode.Success Then
        MessageBox.Show("The Azure Search service does not work for this location.")
        Return
    End If
    Dim resultList As New StringBuilder("")
    Dim resCounter As Integer = 1
    For Each resultInfo As LocationInformation In e.RequestResult.SearchResults
        resultList.Append(String.Format("Result {0}: " & vbCrLf, resCounter))
        resultList.Append(String.Format("Address: {0}" & vbCrLf, resultInfo.Address.FormattedAddress))
        resultList.Append(String.Format("Geographic coordinates: {0}" & vbCrLf, resultInfo.Location))
        resultList.Append(String.Format(" ______________________________" & vbCrLf))
        resCounter += 1
    Next resultInfo
    MessageBox.Show(resultList.ToString())
End Sub
Dim informationLayer As New InformationLayer()
informationLayer.DataProvider = azureSearchProvider
map.Layers.Add(informationLayer)

See Also

AzureSearchDataProvider Class

AzureSearchDataProvider Members

DevExpress.XtraMap Namespace