Back to Devexpress

TdxMapControlAzureMapGeocodeProvider.ExecuteAsync(IdxAzureMapGeocodeQueryParams) Method

vcl-dxazuremapinformationproviders-dot-tdxmapcontrolazuremapgeocodeprovider-dot-executeasync-x28-dxazuremapinterfaces-dot-idxazuremapgeocodequeryparams-x29.md

latest5.2 KB
Original Source

TdxMapControlAzureMapGeocodeProvider.ExecuteAsync(IdxAzureMapGeocodeQueryParams) Method

Sends an asynchronous query to an Azure Maps server.

Declaration

delphi
procedure ExecuteAsync(const AParams: IdxAzureMapGeocodeQueryParams);

Parameters

NameTypeDescription
AParamsIdxAzureMapGeocodeQueryParams

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 geocode query to an Azure Maps server. To cancel pending asynchronous queries, call the CancelRequests 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 Point Coordinates by Address Asynchronously

The code example in this section demonstrates a procedure that sends a query to an Azure Maps Geocode server and an OnResponse event handler that receives and processes the server response. The event handler uses an existing map layer to draw a pushpin at the obtained point coordinates if the query is successful.

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

procedure TMyForm.SendGeocodeQuery(const AAddress: string);
var
  AQueryParams: IdxAzureMapGeocodeQueryParams;
begin
  AQueryParams := dxMapControl1AzureMapGeocodeProvider1.CreateQueryParams;
  AQueryParams.Query := AAddress;
  dxMapControl1AzureMapGeocodeProvider1.ExecuteAsync(AQueryParams);
end;

procedure TMyForm.dxMapControl1AzureMapGeocodeProvider1Response(
  ASender: TdxMapControlAzureMapGeocodeProvider;
  AResponse: TdxAzureMapGeocodeRequestResponse; var ADestroyResponse: Boolean);
var
  APushpin: TdxMapPushpin;
begin
  if AResponse <> nil then
  begin
    if AResponse.IsSuccess then // Creates a pushpin at the obtained position if the query is successful
    begin
      APushpin := dxMapControl1ItemLayer1.MapItems.Add(TdxMapPushpin) as TdxMapPushpin;
      APushpin.Location.GeoPoint.Longitude := AResponse.Features.First.Geometry.Coordinates[0];
      APushpin.Location.GeoPoint.Latitude := AResponse.Features.First.Geometry.Coordinates[1];
    end
    else if Assigned(AResponse.ErrorInfo) then
      dxMessageDlg(AResponse.ErrorInfo.Message, TMsgDlgType.mtError, [mbOK], 0);
  end;
end;
cpp
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapGeocodeProvider
#include "dxMessageDialog.hpp" // Declares the dxMessageDlg global function
// ...

void __fastcall TMyForm::SendGeocodeQuery(const UnicodeString &AAddress)
{
  _di_IdxAzureMapGeocodeQueryParams AQueryParams;
  AQueryParams = dxMapControl1AzureMapGeocodeProvider1->CreateQueryParams();
  AQueryParams->Query = AAddress;
  dxMapControl1AzureMapGeocodeProvider1->ExecuteAsync(AQueryParams);
}

void __fastcall TMyForm::dxMapControl1AzureMapGeocodeProvider1Response(
  TdxMapControlAzureMapGeocodeProvider *ASender,
  TdxAzureMapGeocodeRequestResponse *AResponse, bool &ADestroyResponse)
{
  TdxMapItem *AMapItem;
  TdxMapPushpin *APushpin;
  if(AResponse != nullptr)
  {
    if(AResponse->IsSuccess) // Creates a pushpin at the obtained position if the query is successful
    {
      AMapItem = dxMapControl1ItemLayer1->MapItems->Add(__classid(TdxMapPushpin));
      APushpin = dynamic_cast<TdxMapPushpin*>(AMapItem);
      APushpin->Location->GeoPoint.Longitude = AResponse->Features->First()->Geometry->Coordinates[0];
      APushpin->Location->GeoPoint.Latitude = AResponse->Features->First()->Geometry->Coordinates[1];
    }
    else if(AResponse->ErrorInfo != nullptr)
    {
      dxMessageDlg(AResponse->ErrorInfo->Message, TMsgDlgType::mtError, TMsgDlgButtons() << mbOK, 0);
    }
  }
}

See Also

TdxMapControlAzureMapGeocodeProvider.Execute Procedure

TdxMapControlAzureMapGeocodeProvider Class

TdxMapControlAzureMapGeocodeProvider Members

dxAzureMapInformationProviders Unit