Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cContinentCode
LOCAL nContinentGeoname_id
LOCAL cContinentNamesJa
LOCAL cContinentNamesPt_BR
LOCAL cContinentNamesRu
LOCAL cContinentNamesZh_CN
LOCAL cContinentNamesDe
LOCAL cContinentNamesEn
LOCAL cContinentNamesEs
LOCAL cContinentNamesFr
LOCAL nCountryIs_in_european_union
LOCAL cCountryIso_code
LOCAL nCountryGeoname_id
LOCAL cCountryNamesFr
LOCAL cCountryNamesJa
LOCAL cCountryNamesPt_BR
LOCAL cCountryNamesRu
LOCAL cCountryNamesZh_CN
LOCAL cCountryNamesDe
LOCAL cCountryNamesEn
LOCAL cCountryNamesEs
LOCAL nMaxmindQueries_remaining
LOCAL nRegistered_countryIs_in_european_union
LOCAL cRegistered_countryIso_code
LOCAL nRegistered_countryGeoname_id
LOCAL cRegistered_countryNamesEs
LOCAL cRegistered_countryNamesFr
LOCAL cRegistered_countryNamesJa
LOCAL cRegistered_countryNamesPt_BR
LOCAL cRegistered_countryNamesRu
LOCAL cRegistered_countryNamesZh_CN
LOCAL cRegistered_countryNamesDe
LOCAL cRegistered_countryNamesEn
LOCAL cTraitsIp_address

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

oHttp:Login := "MAXMIND_ACCOUNT_ID"
oHttp:Password := "MAXMIND_LICENSE_KEY"
oHttp:Accept := "application/json"

//  Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
cJsonStr := oHttp:QuickGetStr("https://geoip.maxmind.com/geoip/v2.1/country/149.250.207.170")
IF (oHttp:LastMethodSuccess == 0)
    ? oHttp:LastErrorText
    oHttp:destroy()
    RETURN
ENDIF

oJson := CreateObject("Chilkat.JsonObject")
oJson:EmitCompact := 0
nSuccess := oJson:Load(cJsonStr)

? oJson: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"
//    }
//  }
//  
//  

cContinentCode := oJson:StringOf("continent.code")
nContinentGeoname_id := oJson:IntOf("continent.geoname_id")
cContinentNamesJa := oJson:StringOf("continent.names.ja")
cContinentNamesPt_BR := oJson:StringOf("continent.names.pt-BR")
cContinentNamesRu := oJson:StringOf("continent.names.ru")
cContinentNamesZh_CN := oJson:StringOf("continent.names.zh-CN")
cContinentNamesDe := oJson:StringOf("continent.names.de")
cContinentNamesEn := oJson:StringOf("continent.names.en")
cContinentNamesEs := oJson:StringOf("continent.names.es")
cContinentNamesFr := oJson:StringOf("continent.names.fr")
nCountryIs_in_european_union := oJson:BoolOf("country.is_in_european_union")
cCountryIso_code := oJson:StringOf("country.iso_code")
nCountryGeoname_id := oJson:IntOf("country.geoname_id")
cCountryNamesFr := oJson:StringOf("country.names.fr")
cCountryNamesJa := oJson:StringOf("country.names.ja")
cCountryNamesPt_BR := oJson:StringOf("country.names.pt-BR")
cCountryNamesRu := oJson:StringOf("country.names.ru")
cCountryNamesZh_CN := oJson:StringOf("country.names.zh-CN")
cCountryNamesDe := oJson:StringOf("country.names.de")
cCountryNamesEn := oJson:StringOf("country.names.en")
cCountryNamesEs := oJson:StringOf("country.names.es")
nMaxmindQueries_remaining := oJson:IntOf("maxmind.queries_remaining")
nRegistered_countryIs_in_european_union := oJson:BoolOf("registered_country.is_in_european_union")
cRegistered_countryIso_code := oJson:StringOf("registered_country.iso_code")
nRegistered_countryGeoname_id := oJson:IntOf("registered_country.geoname_id")
cRegistered_countryNamesEs := oJson:StringOf("registered_country.names.es")
cRegistered_countryNamesFr := oJson:StringOf("registered_country.names.fr")
cRegistered_countryNamesJa := oJson:StringOf("registered_country.names.ja")
cRegistered_countryNamesPt_BR := oJson:StringOf("registered_country.names.pt-BR")
cRegistered_countryNamesRu := oJson:StringOf("registered_country.names.ru")
cRegistered_countryNamesZh_CN := oJson:StringOf("registered_country.names.zh-CN")
cRegistered_countryNamesDe := oJson:StringOf("registered_country.names.de")
cRegistered_countryNamesEn := oJson:StringOf("registered_country.names.en")
cTraitsIp_address := oJson:StringOf("traits.ip_address")

oHttp:destroy()
oJson:destroy()