Sample code for 30+ languages & platforms
Xbase++

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

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cIp
LOCAL cCity
LOCAL cRegion
LOCAL cRegion_code
LOCAL cCountry
LOCAL cCountry_name
LOCAL cContinent_code
LOCAL nIn_eu
LOCAL cPostal
LOCAL cLatitude
LOCAL cLongitude
LOCAL cTimezone
LOCAL cUtc_offset
LOCAL cCountry_calling_code
LOCAL cCurrency
LOCAL cLanguages
LOCAL cAsn
LOCAL cOrg

nSuccess := 0

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

oHttp := CreateObject("Chilkat.Http")

//  Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
cJsonStr := oHttp:QuickGetStr("https://ipapi.co/149.250.207.170/json")
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

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

cIp := oJson:StringOf("ip")
cCity := oJson:StringOf("city")
cRegion := oJson:StringOf("region")
cRegion_code := oJson:StringOf("region_code")
cCountry := oJson:StringOf("country")
cCountry_name := oJson:StringOf("country_name")
cContinent_code := oJson:StringOf("continent_code")
nIn_eu := oJson:BoolOf("in_eu")
cPostal := oJson:StringOf("postal")
cLatitude := oJson:StringOf("latitude")
cLongitude := oJson:StringOf("longitude")
cTimezone := oJson:StringOf("timezone")
cUtc_offset := oJson:StringOf("utc_offset")
cCountry_calling_code := oJson:StringOf("country_calling_code")
cCurrency := oJson:StringOf("currency")
cLanguages := oJson:StringOf("languages")
cAsn := oJson:StringOf("asn")
cOrg := oJson:StringOf("org")

oHttp:destroy()
oJson:destroy()