Back to Devexpress

TdxMapControlAzureMapGeolocationProvider.Execute(IdxAzureMapQueryParams,TdxAzureMapGeolocationRequestResponse) Method

vcl-dxazuremapinformationproviders-dot-tdxmapcontrolazuremapgeolocationprovider-dot-execute-x28-idxazuremapqueryparams-tdxazuremapgeolocationrequestresponse-x29.md

latest4.4 KB
Original Source

TdxMapControlAzureMapGeolocationProvider.Execute(IdxAzureMapQueryParams,TdxAzureMapGeolocationRequestResponse) Method

Sends a query to an Azure Maps server and returns the result.

Declaration

delphi
procedure Execute(const AParams: IdxAzureMapQueryParams; out AGeolocationResponse: TdxAzureMapGeolocationRequestResponse);

Parameters

NameTypeDescription
AParamsIdxAzureMapQueryParams

Accepts a configured query parameters container.

Call the CreateQueryParams function to create a query parameters container.

| | AGeolocationResponse | TdxAzureMapGeolocationRequestResponse |

Returns a container populated with information returned by a server.

Important

Every Execute procedure call creates a new TdxAzureMapGeolocationRequestResponse class instance.

Call the Free procedure (in Delphi) or use the delete keyword (in C++Builder) to destroy TdxAzureMapGeolocationRequestResponse class instances manually to avoid memory leaks.

|

Remarks

Call the Execute procedure to send a geolocation query to an Azure Maps server and wait for a response returned as the AGeolocationResponse parameter.

Code Example: Obtain Country ISO Code by IP Address

The following code example implements a function that uses a configured information provider to return a country ISO code that corresponds to the specified IP address:

delphi
uses
  dxAzureMapInformationProviders; // Declares TdxMapControlAzureMapGeolocationProvider
// ...

function TMyForm.GetCountryISOCode(const AIPAddress: string): string;
var
  AParams: IdxAzureMapGeolocationQueryParams;
  AResponse: TdxAzureMapGeolocationRequestResponse;
begin
  AParams := dxMapControl1AzureMapGeolocationProvider1.CreateQueryParams;
  AParams.IP := AIPAddress;
  dxMapControl1AzureMapGeolocationProvider1.Execute(AParams, AResponse);
  if AResponse <> nil then
  begin
    if AResponse.IsSuccess then
      AResult := AResponse.CountryRegion.IsoCode
  end;
end;
cpp
#include "dxAzureMapInformationProviders.hpp" // Declares TdxMapControlAzureMapGeolocationProvider
// ...

UnicodeString __fastcall TMyForm::GetCountryISOCode(const UnicodeString &AIPAddress)
{
  _di_IdxAzureMapGeolocationQueryParams AParams;
  TdxAzureMapGeolocationRequestResponse *AResponse;
  UnicodeString AResult;

  AParams = dxMapControl1AzureMapGeolocationProvider1->CreateQueryParams();
  AParams->IP = AIPAddress;
  dxMapControl1AzureMapGeolocationProvider1->Execute(AParams, AResponse);
  if(AResponse != nullptr)
  {
    if(AResponse->IsSuccess)
      AResult = AResponse->CountryRegion->IsoCode;
  }
  return AResult;
}

Asynchronous Queries and Server Response

The Execute procedure runs in the main thread and, therefore, locks the application UI until the corresponding server response or a timeout error.

To keep your UI responsive, you can call the ExecuteAsync procedure instead. Handle the OnResponse event to process a server response when the information provider receives it.

See Also

TdxMapControlAzureMapGeolocationProvider Class

TdxMapControlAzureMapGeolocationProvider Members

dxAzureMapInformationProviders Unit