Back to Devexpress

TdxMapControlAzureMapReverseGeocodeProvider.OnResponse Event

vcl-dxazuremapinformationproviders-dot-tdxmapcontrolazuremapreversegeocodeprovider-6a14c585.md

latest6.3 KB
Original Source

TdxMapControlAzureMapReverseGeocodeProvider.OnResponse Event

Allows you to accept and process responses from an Azure Maps server.

Declaration

delphi
property OnResponse: TdxAzureMapReverseGeocodeProviderOnResponse read; write;

Remarks

Handle the OnResponse event to receive and process responses from an Azure Maps server after an ExecuteAsync procedure call.

Event Occurrence

The OnResponse event occurs every time an Azure Maps server sends a response after an ExecuteAsync procedure call.

Event Parameters

The following parameters are available within an OnResponse event handler:

ASenderProvides access to the TdxMapControlAzureMapReverseGeocodeProvider component that raised the server response event.AResponseProvides access to a container populated with information returned by a server.ADestroyResponse

Specifies if the OnResponse event handler automatically destroys the information container accessible through the AResponse parameter.

If this parameter value is True, the container is destroyed once the application exits the current OnResponse event handler. Otherwise, you need to release the container manually.

Refer to the TdxAzureMapReverseGeocodeProviderOnResponse procedural type description for detailed information on all available options.

Code Example: Obtain Map Point Address Asynchronously

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

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

procedure TMyForm.AddPushpin(AGeoPoint: TdxMapControlGeoPoint): Boolean;
var
  APushpin: TdxMapPushpin;
  AQueryParams: IdxAzureMapReverseGeocodeQueryParams;
begin
  // Creates a new pushpin on an existing map item layer
  APushpin := dxMapControl1ItemLayer1.MapItems.Add(TdxMapPushpin) as TdxMapPushpin;
  APushpin.Location.GeoPoint := AGeoPoint;
  AQueryParams := dxMapControl1AzureMapReverseGeocodeProvider1.CreateQueryParams;
  AQueryParams.Coordinates := APushpin.Location.GeoPoint;
  // Uses a configured reverse geocode provider to send a query to an Azure Maps server
  dxMapControl1AzureMapReverseGeocodeProvider1.ExecuteAsync(AQueryParams);
end;

procedure TMyForm.dxMapControl1AzureMapReverseGeocodeProvider1Response(
  ASender: TdxMapControlAzureMapReverseGeocodeProvider;
  AResponse: TdxAzureMapReverseGeocodeRequestResponse; var ADestroyResponse: Boolean);
var
  AMapItems: TdxMapItems;
  APushpin: TdxMapPushpin;
begin
  AMapItems := dxMapControl1ItemLayer1.MapItems;
  if AResponse <> nil then
  begin
    if AResponse.IsSuccess and (AResponse.Features.Count > 0) then // Checks if the query is successful
    begin
      APushpin := AMapItems.Items[AMapItems.Count - 1] as TdxMapPushpin;
      APushpin.Hint := AResponse.Features.First.Properties.Address.FormattedAddress;
    end
    else if Assigned(AResponse.ErrorInfo) then
      dxMessageDlg(AResponse.ErrorInfo.Message, TMsgDlgType.mtError, [mkOK], 0);
  end;
end;
cpp
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapReverseGeocodeProvider
#include "dxMessageDialog.hpp" // Declares the dxMessageDlg global function
// ...

void __fastcall TMyForm::AddPushpin(TdxMapControlGeoPoint *AGeoPoint)
{
  TdxMapPushpin *APushpin;
  _di_IdxAzureMapReverseGeocodeQueryParams AQueryParams;
  // Creates a new pushpin on an existing map item layer
  APushpin = dynamic_cast<TdxMapPushpin*>(dxMapControl1ItemLayer1->MapItems->Add(__classid(TdxMapPushpin)));
  APushpin->Location->GeoPoint = AGeoPoint;
  AQueryParams = dxMapControl1AzureMapReverseGeocodeProvider1->CreateQueryParams();
  AQueryParams->Coordinates = APushpin->Location->GeoPoint;
  // Uses a configured reverse geocode provider to send a query to an Azure Maps server
  dxMapControl1AzureMapReverseGeocodeProvider1->ExecuteAsync(AQueryParams);
}

void __fastcall TMyForm::dxMapControl1AzureMapReverseGeocodeProvider1Response(
  TdxMapControlAzureMapReverseGeocodeProvider *ASender,
  TdxAzureMapReverseGeocodeRequestResponse *AResponse, bool &ADestroyResponse)
{
  TdxMapItems *AMapItems;
  TdxMapPushpin *APushpin;
  AMapItems = dxMapControl1ItemLayer1->MapItems;
  if(AResponse != nullptr)
  {
    if((AResponse->IsSuccess) && (AResponse->Features->Count > 0)) // Checks if the query is successful
    {
      APushpin = dynamic_cast<TdxMapPushpin*>(AMapItems->Items[AMapItems->Count - 1]);
      APushpin->Hint = AResponse->Features->Properties->Address->FormattedAddress;
    }
    else if(AResponse->ErrorInfo != nullptr)
    {
      dxMessageDlg(AResponse->ErrorInfo->Message, TMsgDlgType::mtError, TMsgDlgButtons() << mbOK, 0);
    }
  }
}

See Also

TdxMapControlAzureMapReverseGeocodeProvider.Execute Procedure

TdxMapControlAzureMapReverseGeocodeProvider Class

TdxMapControlAzureMapReverseGeocodeProvider Members

dxAzureMapInformationProviders Unit