Back to Devexpress

TdxMapControlAzureMapGeolocationProvider.ExecuteAsync(IdxAzureMapQueryParams) Method

vcl-dxazuremapinformationproviders-dot-tdxmapcontrolazuremapgeolocationprovider-dot-executeasync-x28-dxazuremapinterfaces-dot-idxazuremapqueryparams-x29.md

latest4.5 KB
Original Source

TdxMapControlAzureMapGeolocationProvider.ExecuteAsync(IdxAzureMapQueryParams) Method

Sends an asynchronous query to an Azure Maps server.

Declaration

delphi
procedure ExecuteAsync(const AParams: IdxAzureMapQueryParams);

Parameters

NameTypeDescription
AParamsIdxAzureMapQueryParams

Accepts a configured query parameters container.

Call the CreateQueryParams function to create a query parameters container.

|

Remarks

Call the ExecuteAsync procedure to send an asynchronous geolocation query to an Azure Maps server. To cancel pending asynchronous queries, call the CancelRequest procedure.

Receive Server Responses to Asynchronous Queries

Handle the OnResponse event to receive and process a server query after an ExecuteAsync procedure call.

Code Example: Obtain Country ISO Code by IP Address Asynchronously

The code example in this section demonstrates a procedure that sends a query to an Azure Maps Geolocation server and an OnResponse event handler that receives and processes the server response.

delphi
uses
  dxAzureMapInformationProviders, // Declares TdxMapControlAzureMapGeolocationProvider
  dxMessageDialog; // Declares the dxMessageDlg global function
// ...

procedure TMyForm.SendGeolocationQuery(const AIPAddress: string);
var
  AQueryParams: IdxAzureMapGeolocationQueryParams;
begin
  AQueryParams := dxMapControl1AzureMapGeolocationProvider1.CreateQueryParams;
  AQueryParams.IP := AIPAddress;
  dxMapControl1AzureMapGeolocationProvider1.ExecuteAsync(AQueryParams);
end;

procedure TMyForm.dxMapControl1AzureMapGeolocationProvider1Response(
  ASender: TdxMapControlAzureMapGeolocationProvider;
  AResponse: TdxAzureMapGeolocationRequestResponse; var ADestroyResponse: Boolean);
begin
  if AResponse <> nil then
  begin
    if AResponse.IsSuccess then
      dxMessageDlg('Country Code: ' + AResponse.CountryRegion.IsoCode, TMsgDlgType.mtInformation, [mbOK], 0);
    else if Assigned(AResponse.ErrorInfo) then
      dxMessageDlg(AResponse.ErrorInfo.Message, TMsgDlgType.mtError, [mbOK], 0);
  end;
end;
cpp
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapGeolocationProvider
#include "dxMessageDialog.hpp" // Declares the dxMessageDlg global function
// ...

void __fastcall TMyForm::SendGeolocationQuery(const UnicodeString &AIPAddress)
{
  _di_IdxAzureMapGeolocationQueryParams AQueryParams;
  AQueryParams = dxMapControl1AzureMapGeolocationProvider1->CreateQueryParams();
  AQueryParams->IP = AIPAddress;
  dxMapControl1AzureMapGeolocationProvider1->ExecuteAsync(AQueryParams);
}

void __fastcall TMyForm::dxMapControl1AzureMapGeolocationProviderResponse(
  TdxMapControlAzureMapGeolocationProvider *ASender,
  TdxAzureMapGeolocationRequestResponse *AResponse, bool &ADestroyResponse)
{
  if(AResponse != nullptr)
  {
    if(AResponse->IsSuccess)
    {
      dxMessageDlg("Country Code: " + AResponse->CountryRegion->IsoCode,
        TMsgDlgType::mtInformation, TMsgDlgButtons() << mbOK, 0);
    }
    else if(AResponse->ErrorInfo != nullptr)
    {
      dxMessageDlg(AResponse->ErrorInfo->Message, TMsgDlgType::mtError, TMsgDlgButtons() << mbOK, 0);
    }
  }
}

See Also

TdxMapControlAzureMapGeolocationProvider.Execute Procedure

TdxMapControlAzureMapGeolocationProvider Class

TdxMapControlAzureMapGeolocationProvider Members

dxAzureMapInformationProviders Unit