Delphi DLL
Delphi DLL
ipapi.co IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipapi.co REST API.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Http;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonStr: PWideChar;
json: HCkJsonObject;
ip: PWideChar;
city: PWideChar;
region: PWideChar;
region_code: PWideChar;
country: PWideChar;
country_name: PWideChar;
continent_code: PWideChar;
in_eu: Boolean;
postal: PWideChar;
latitude: PWideChar;
longitude: PWideChar;
timezone: PWideChar;
utc_offset: PWideChar;
country_calling_code: PWideChar;
currency: PWideChar;
languages: PWideChar;
asn: PWideChar;
org: PWideChar;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
jsonStr := CkHttp__quickGetStr(http,'https://ipapi.co/149.250.207.170/json');
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
json := CkJsonObject_Create();
CkJsonObject_putEmitCompact(json,False);
success := CkJsonObject_Load(json,jsonStr);
Memo1.Lines.Add(CkJsonObject__emit(json));
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "ip": "149.250.207.170",
// "city": "B�blingen",
// "region": "Baden-W�rttemberg",
// "region_code": null,
// "country": "DE",
// "country_name": "Germany",
// "continent_code": "EU",
// "in_eu": true,
// "postal": null,
// "latitude": null,
// "longitude": null,
// "timezone": null,
// "utc_offset": null,
// "country_calling_code": "+49",
// "currency": "EUR",
// "languages": "de",
// "asn": "AS15854",
// "org": "EntServ Deutschland GmbH"
// }
ip := CkJsonObject__stringOf(json,'ip');
city := CkJsonObject__stringOf(json,'city');
region := CkJsonObject__stringOf(json,'region');
region_code := CkJsonObject__stringOf(json,'region_code');
country := CkJsonObject__stringOf(json,'country');
country_name := CkJsonObject__stringOf(json,'country_name');
continent_code := CkJsonObject__stringOf(json,'continent_code');
in_eu := CkJsonObject_BoolOf(json,'in_eu');
postal := CkJsonObject__stringOf(json,'postal');
latitude := CkJsonObject__stringOf(json,'latitude');
longitude := CkJsonObject__stringOf(json,'longitude');
timezone := CkJsonObject__stringOf(json,'timezone');
utc_offset := CkJsonObject__stringOf(json,'utc_offset');
country_calling_code := CkJsonObject__stringOf(json,'country_calling_code');
currency := CkJsonObject__stringOf(json,'currency');
languages := CkJsonObject__stringOf(json,'languages');
asn := CkJsonObject__stringOf(json,'asn');
org := CkJsonObject__stringOf(json,'org');
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
end;