Sample code for 30+ languages & platforms
Delphi DLL

geo.ipify.org IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the geo.ipify.org REST API.

Chilkat Delphi DLL Downloads

Delphi DLL
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;
locationCountry: PWideChar;
locationRegion: PWideChar;
locationCity: PWideChar;
locationLat: PWideChar;
locationLng: PWideChar;
locationPostalCode: PWideChar;
locationTimezone: 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: 8.8.8.8
jsonStr := CkHttp__quickGetStr(http,'https://geo.ipify.org/api/v1?apiKey=API_KEY&ipAddress=8.8.8.8');
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": "8.8.8.8",
//   "location": {
//     "country": "IT",
//     "region": "Lombardy",
//     "city": "Milan",
//     "lat": 45.4707,
//     "lng": 9.1889,
//     "postalCode": "20147",
//     "timezone": "+02:00"
//   }
// }

ip := CkJsonObject__stringOf(json,'ip');
locationCountry := CkJsonObject__stringOf(json,'location.country');
locationRegion := CkJsonObject__stringOf(json,'location.region');
locationCity := CkJsonObject__stringOf(json,'location.city');
locationLat := CkJsonObject__stringOf(json,'location.lat');
locationLng := CkJsonObject__stringOf(json,'location.lng');
locationPostalCode := CkJsonObject__stringOf(json,'location.postalCode');
locationTimezone := CkJsonObject__stringOf(json,'location.timezone');

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);

end;