Unicode C++
Unicode C++
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 Unicode C++ Downloads
#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;
http.put_Login(L"MAXMIND_ACCOUNT_ID");
http.put_Password(L"MAXMIND_LICENSE_KEY");
http.put_Accept(L"application/json");
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
const wchar_t *jsonStr = http.quickGetStr(L"https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170");
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
// {
// "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"
// }
// }
//
//
const wchar_t *continentCode = 0;
int continentGeoname_id;
const wchar_t *continentNamesJa = 0;
const wchar_t *continentNamesPt_BR = 0;
const wchar_t *continentNamesRu = 0;
const wchar_t *continentNamesZh_CN = 0;
const wchar_t *continentNamesDe = 0;
const wchar_t *continentNamesEn = 0;
const wchar_t *continentNamesEs = 0;
const wchar_t *continentNamesFr = 0;
bool countryIs_in_european_union;
const wchar_t *countryIso_code = 0;
int countryGeoname_id;
const wchar_t *countryNamesFr = 0;
const wchar_t *countryNamesJa = 0;
const wchar_t *countryNamesPt_BR = 0;
const wchar_t *countryNamesRu = 0;
const wchar_t *countryNamesZh_CN = 0;
const wchar_t *countryNamesDe = 0;
const wchar_t *countryNamesEn = 0;
const wchar_t *countryNamesEs = 0;
int maxmindQueries_remaining;
bool registered_countryIs_in_european_union;
const wchar_t *registered_countryIso_code = 0;
int registered_countryGeoname_id;
const wchar_t *registered_countryNamesEs = 0;
const wchar_t *registered_countryNamesFr = 0;
const wchar_t *registered_countryNamesJa = 0;
const wchar_t *registered_countryNamesPt_BR = 0;
const wchar_t *registered_countryNamesRu = 0;
const wchar_t *registered_countryNamesZh_CN = 0;
const wchar_t *registered_countryNamesDe = 0;
const wchar_t *registered_countryNamesEn = 0;
const wchar_t *traitsIp_address = 0;
continentCode = json.stringOf(L"continent.code");
continentGeoname_id = json.IntOf(L"continent.geoname_id");
continentNamesJa = json.stringOf(L"continent.names.ja");
continentNamesPt_BR = json.stringOf(L"continent.names.pt-BR");
continentNamesRu = json.stringOf(L"continent.names.ru");
continentNamesZh_CN = json.stringOf(L"continent.names.zh-CN");
continentNamesDe = json.stringOf(L"continent.names.de");
continentNamesEn = json.stringOf(L"continent.names.en");
continentNamesEs = json.stringOf(L"continent.names.es");
continentNamesFr = json.stringOf(L"continent.names.fr");
countryIs_in_european_union = json.BoolOf(L"country.is_in_european_union");
countryIso_code = json.stringOf(L"country.iso_code");
countryGeoname_id = json.IntOf(L"country.geoname_id");
countryNamesFr = json.stringOf(L"country.names.fr");
countryNamesJa = json.stringOf(L"country.names.ja");
countryNamesPt_BR = json.stringOf(L"country.names.pt-BR");
countryNamesRu = json.stringOf(L"country.names.ru");
countryNamesZh_CN = json.stringOf(L"country.names.zh-CN");
countryNamesDe = json.stringOf(L"country.names.de");
countryNamesEn = json.stringOf(L"country.names.en");
countryNamesEs = json.stringOf(L"country.names.es");
maxmindQueries_remaining = json.IntOf(L"maxmind.queries_remaining");
registered_countryIs_in_european_union = json.BoolOf(L"registered_country.is_in_european_union");
registered_countryIso_code = json.stringOf(L"registered_country.iso_code");
registered_countryGeoname_id = json.IntOf(L"registered_country.geoname_id");
registered_countryNamesEs = json.stringOf(L"registered_country.names.es");
registered_countryNamesFr = json.stringOf(L"registered_country.names.fr");
registered_countryNamesJa = json.stringOf(L"registered_country.names.ja");
registered_countryNamesPt_BR = json.stringOf(L"registered_country.names.pt-BR");
registered_countryNamesRu = json.stringOf(L"registered_country.names.ru");
registered_countryNamesZh_CN = json.stringOf(L"registered_country.names.zh-CN");
registered_countryNamesDe = json.stringOf(L"registered_country.names.de");
registered_countryNamesEn = json.stringOf(L"registered_country.names.en");
traitsIp_address = json.stringOf(L"traits.ip_address");
}