Delphi DLL
Delphi DLL
ipdata.co IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipdata.co 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;
is_eu: Boolean;
city: PWideChar;
region: PWideChar;
region_code: PWideChar;
country_name: PWideChar;
country_code: PWideChar;
continent_name: PWideChar;
continent_code: PWideChar;
latitude: PWideChar;
longitude: PWideChar;
asn: PWideChar;
organisation: PWideChar;
postal: PWideChar;
calling_code: PWideChar;
flag: PWideChar;
emoji_flag: PWideChar;
emoji_unicode: PWideChar;
currencyName: PWideChar;
currencyCode: PWideChar;
currencySymbol: PWideChar;
currencyNative: PWideChar;
currencyPlural: PWideChar;
time_zoneName: PWideChar;
time_zoneAbbr: PWideChar;
time_zoneOffset: PWideChar;
time_zoneIs_dst: Boolean;
time_zoneCurrent_time: PWideChar;
threatIs_tor: Boolean;
threatIs_proxy: Boolean;
threatIs_anonymous: Boolean;
threatIs_known_attacker: Boolean;
threatIs_known_abuser: Boolean;
threatIs_threat: Boolean;
threatIs_bogon: Boolean;
count: PWideChar;
i: Integer;
count_i: Integer;
name: PWideChar;
native: 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();
jsonStr := CkHttp__quickGetStr(http,'https://api.ipdata.co/149.250.207.170?api-key=MY_API_KEY');
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",
// "is_eu": true,
// "city": null,
// "region": null,
// "region_code": null,
// "country_name": "Germany",
// "country_code": "DE",
// "continent_name": "Europe",
// "continent_code": "EU",
// "latitude": 51.2993,
// "longitude": 9.491,
// "asn": "AS15854",
// "organisation": "EntServ Deutschland GmbH",
// "postal": null,
// "calling_code": "49",
// "flag": "https://ipdata.co/flags/de.png",
// "emoji_flag": "\ud83c\udde9\ud83c\uddea",
// "emoji_unicode": "U+1F1E9 U+1F1EA",
// "languages": [
// {
// "name": "German",
// "native": "Deutsch"
// }
// ],
// "currency": {
// "name": "Euro",
// "code": "EUR",
// "symbol": "\u20ac",
// "native": "\u20ac",
// "plural": "euros"
// },
// "time_zone": {
// "name": "Europe/Berlin",
// "abbr": "CEST",
// "offset": "+0200",
// "is_dst": true,
// "current_time": "2019-04-20T23:54:30.715507+02:00"
// },
// "threat": {
// "is_tor": false,
// "is_proxy": false,
// "is_anonymous": false,
// "is_known_attacker": false,
// "is_known_abuser": false,
// "is_threat": false,
// "is_bogon": false
// },
// "count": "2"
// }
ip := CkJsonObject__stringOf(json,'ip');
is_eu := CkJsonObject_BoolOf(json,'is_eu');
city := CkJsonObject__stringOf(json,'city');
region := CkJsonObject__stringOf(json,'region');
region_code := CkJsonObject__stringOf(json,'region_code');
country_name := CkJsonObject__stringOf(json,'country_name');
country_code := CkJsonObject__stringOf(json,'country_code');
continent_name := CkJsonObject__stringOf(json,'continent_name');
continent_code := CkJsonObject__stringOf(json,'continent_code');
latitude := CkJsonObject__stringOf(json,'latitude');
longitude := CkJsonObject__stringOf(json,'longitude');
asn := CkJsonObject__stringOf(json,'asn');
organisation := CkJsonObject__stringOf(json,'organisation');
postal := CkJsonObject__stringOf(json,'postal');
calling_code := CkJsonObject__stringOf(json,'calling_code');
flag := CkJsonObject__stringOf(json,'flag');
emoji_flag := CkJsonObject__stringOf(json,'emoji_flag');
emoji_unicode := CkJsonObject__stringOf(json,'emoji_unicode');
currencyName := CkJsonObject__stringOf(json,'currency.name');
currencyCode := CkJsonObject__stringOf(json,'currency.code');
currencySymbol := CkJsonObject__stringOf(json,'currency.symbol');
currencyNative := CkJsonObject__stringOf(json,'currency.native');
currencyPlural := CkJsonObject__stringOf(json,'currency.plural');
time_zoneName := CkJsonObject__stringOf(json,'time_zone.name');
time_zoneAbbr := CkJsonObject__stringOf(json,'time_zone.abbr');
time_zoneOffset := CkJsonObject__stringOf(json,'time_zone.offset');
time_zoneIs_dst := CkJsonObject_BoolOf(json,'time_zone.is_dst');
time_zoneCurrent_time := CkJsonObject__stringOf(json,'time_zone.current_time');
threatIs_tor := CkJsonObject_BoolOf(json,'threat.is_tor');
threatIs_proxy := CkJsonObject_BoolOf(json,'threat.is_proxy');
threatIs_anonymous := CkJsonObject_BoolOf(json,'threat.is_anonymous');
threatIs_known_attacker := CkJsonObject_BoolOf(json,'threat.is_known_attacker');
threatIs_known_abuser := CkJsonObject_BoolOf(json,'threat.is_known_abuser');
threatIs_threat := CkJsonObject_BoolOf(json,'threat.is_threat');
threatIs_bogon := CkJsonObject_BoolOf(json,'threat.is_bogon');
count := CkJsonObject__stringOf(json,'count');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'languages');
while i < count_i do
begin
CkJsonObject_putI(json,i);
name := CkJsonObject__stringOf(json,'languages[i].name');
native := CkJsonObject__stringOf(json,'languages[i].native');
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
end;