Sample code for 30+ languages & platforms
Unicode C++

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 Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;

    // Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
    const wchar_t *jsonStr = http.quickGetStr(L"https://ipapi.co/149.250.207.170/json");
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW json;
    json.put_EmitCompact(false);
    success = json.Load(jsonStr);

    wprintf(L"%s\n",json.emit());

    // 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"
    // }

    const wchar_t *ip = 0;
    const wchar_t *city = 0;
    const wchar_t *region = 0;
    const wchar_t *region_code = 0;
    const wchar_t *country = 0;
    const wchar_t *country_name = 0;
    const wchar_t *continent_code = 0;
    bool in_eu;
    const wchar_t *postal = 0;
    const wchar_t *latitude = 0;
    const wchar_t *longitude = 0;
    const wchar_t *timezone = 0;
    const wchar_t *utc_offset = 0;
    const wchar_t *country_calling_code = 0;
    const wchar_t *currency = 0;
    const wchar_t *languages = 0;
    const wchar_t *asn = 0;
    const wchar_t *org = 0;

    ip = json.stringOf(L"ip");
    city = json.stringOf(L"city");
    region = json.stringOf(L"region");
    region_code = json.stringOf(L"region_code");
    country = json.stringOf(L"country");
    country_name = json.stringOf(L"country_name");
    continent_code = json.stringOf(L"continent_code");
    in_eu = json.BoolOf(L"in_eu");
    postal = json.stringOf(L"postal");
    latitude = json.stringOf(L"latitude");
    longitude = json.stringOf(L"longitude");
    timezone = json.stringOf(L"timezone");
    utc_offset = json.stringOf(L"utc_offset");
    country_calling_code = json.stringOf(L"country_calling_code");
    currency = json.stringOf(L"currency");
    languages = json.stringOf(L"languages");
    asn = json.stringOf(L"asn");
    org = json.stringOf(L"org");
    }