Delphi DLL
Delphi DLL
MaxMind IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.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;
continentCode: PWideChar;
continentGeoname_id: Integer;
continentNamesJa: PWideChar;
continentNamesPt_BR: PWideChar;
continentNamesRu: PWideChar;
continentNamesZh_CN: PWideChar;
continentNamesDe: PWideChar;
continentNamesEn: PWideChar;
continentNamesEs: PWideChar;
continentNamesFr: PWideChar;
countryIs_in_european_union: Boolean;
countryIso_code: PWideChar;
countryGeoname_id: Integer;
countryNamesFr: PWideChar;
countryNamesJa: PWideChar;
countryNamesPt_BR: PWideChar;
countryNamesRu: PWideChar;
countryNamesZh_CN: PWideChar;
countryNamesDe: PWideChar;
countryNamesEn: PWideChar;
countryNamesEs: PWideChar;
maxmindQueries_remaining: Integer;
registered_countryIs_in_european_union: Boolean;
registered_countryIso_code: PWideChar;
registered_countryGeoname_id: Integer;
registered_countryNamesEs: PWideChar;
registered_countryNamesFr: PWideChar;
registered_countryNamesJa: PWideChar;
registered_countryNamesPt_BR: PWideChar;
registered_countryNamesRu: PWideChar;
registered_countryNamesZh_CN: PWideChar;
registered_countryNamesDe: PWideChar;
registered_countryNamesEn: PWideChar;
traitsIp_address: 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();
CkHttp_putLogin(http,'MAXMIND_ACCOUNT_ID');
CkHttp_putPassword(http,'MAXMIND_LICENSE_KEY');
CkHttp_putAccept(http,'application/json');
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
jsonStr := CkHttp__quickGetStr(http,'https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170');
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
// {
// "continent": {
// "code": "EU",
// "geoname_id": 6255148,
// "names": {
// "ja": "?????",
// "pt-BR": "Europa",
// "ru": "??????",
// "zh-CN": "??",
// "de": "Europa",
// "en": "Europe",
// "es": "Europa",
// "fr": "Europe"
// }
// },
// "country": {
// "is_in_european_union": true,
// "iso_code": "DE",
// "geoname_id": 2921044,
// "names": {
// "fr": "Allemagne",
// "ja": "????????",
// "pt-BR": "Alemanha",
// "ru": "????????",
// "zh-CN": "??",
// "de": "Deutschland",
// "en": "Germany",
// "es": "Alemania"
// }
// },
// "maxmind": {
// "queries_remaining": 49999
// },
// "registered_country": {
// "is_in_european_union": true,
// "iso_code": "DE",
// "geoname_id": 2921044,
// "names": {
// "es": "Alemania",
// "fr": "Allemagne",
// "ja": "????????",
// "pt-BR": "Alemanha",
// "ru": "????????",
// "zh-CN": "??",
// "de": "Deutschland",
// "en": "Germany"
// }
// },
// "traits": {
// "ip_address": "149.250.207.170"
// }
// }
//
//
continentCode := CkJsonObject__stringOf(json,'continent.code');
continentGeoname_id := CkJsonObject_IntOf(json,'continent.geoname_id');
continentNamesJa := CkJsonObject__stringOf(json,'continent.names.ja');
continentNamesPt_BR := CkJsonObject__stringOf(json,'continent.names.pt-BR');
continentNamesRu := CkJsonObject__stringOf(json,'continent.names.ru');
continentNamesZh_CN := CkJsonObject__stringOf(json,'continent.names.zh-CN');
continentNamesDe := CkJsonObject__stringOf(json,'continent.names.de');
continentNamesEn := CkJsonObject__stringOf(json,'continent.names.en');
continentNamesEs := CkJsonObject__stringOf(json,'continent.names.es');
continentNamesFr := CkJsonObject__stringOf(json,'continent.names.fr');
countryIs_in_european_union := CkJsonObject_BoolOf(json,'country.is_in_european_union');
countryIso_code := CkJsonObject__stringOf(json,'country.iso_code');
countryGeoname_id := CkJsonObject_IntOf(json,'country.geoname_id');
countryNamesFr := CkJsonObject__stringOf(json,'country.names.fr');
countryNamesJa := CkJsonObject__stringOf(json,'country.names.ja');
countryNamesPt_BR := CkJsonObject__stringOf(json,'country.names.pt-BR');
countryNamesRu := CkJsonObject__stringOf(json,'country.names.ru');
countryNamesZh_CN := CkJsonObject__stringOf(json,'country.names.zh-CN');
countryNamesDe := CkJsonObject__stringOf(json,'country.names.de');
countryNamesEn := CkJsonObject__stringOf(json,'country.names.en');
countryNamesEs := CkJsonObject__stringOf(json,'country.names.es');
maxmindQueries_remaining := CkJsonObject_IntOf(json,'maxmind.queries_remaining');
registered_countryIs_in_european_union := CkJsonObject_BoolOf(json,'registered_country.is_in_european_union');
registered_countryIso_code := CkJsonObject__stringOf(json,'registered_country.iso_code');
registered_countryGeoname_id := CkJsonObject_IntOf(json,'registered_country.geoname_id');
registered_countryNamesEs := CkJsonObject__stringOf(json,'registered_country.names.es');
registered_countryNamesFr := CkJsonObject__stringOf(json,'registered_country.names.fr');
registered_countryNamesJa := CkJsonObject__stringOf(json,'registered_country.names.ja');
registered_countryNamesPt_BR := CkJsonObject__stringOf(json,'registered_country.names.pt-BR');
registered_countryNamesRu := CkJsonObject__stringOf(json,'registered_country.names.ru');
registered_countryNamesZh_CN := CkJsonObject__stringOf(json,'registered_country.names.zh-CN');
registered_countryNamesDe := CkJsonObject__stringOf(json,'registered_country.names.de');
registered_countryNamesEn := CkJsonObject__stringOf(json,'registered_country.names.en');
traitsIp_address := CkJsonObject__stringOf(json,'traits.ip_address');
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
end;