Sample code for 30+ languages & platforms
Xbase++

ip-api.com IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the ip-api.com API.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cAs
LOCAL cCity
LOCAL cCountry
LOCAL cCountryCode
LOCAL cIsp
LOCAL cLat
LOCAL cLon
LOCAL cOrg
LOCAL cQuery
LOCAL cRegion
LOCAL cRegionName
LOCAL cStatus
LOCAL cTimezone
LOCAL cZip

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("http://ip-api.com/json/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

//  {
//    "as": "AS15854 Hewlett Packard GmbH",
//    "city": "B�blingen",
//    "country": "Germany",
//    "countryCode": "DE",
//    "isp": "Triaton Frankfurt",
//    "lat": 48.6779,
//    "lon": 8.97297,
//    "org": "EntServ Deutschland GmbH",
//    "query": "149.250.207.170",
//    "region": "BW",
//    "regionName": "Baden-W�rttemberg",
//    "status": "success",
//    "timezone": "Europe/Berlin",
//    "zip": "71034"
//  }

cAs := oJson:StringOf("as")
cCity := oJson:StringOf("city")
cCountry := oJson:StringOf("country")
cCountryCode := oJson:StringOf("countryCode")
cIsp := oJson:StringOf("isp")
cLat := oJson:StringOf("lat")
cLon := oJson:StringOf("lon")
cOrg := oJson:StringOf("org")
cQuery := oJson:StringOf("query")
cRegion := oJson:StringOf("region")
cRegionName := oJson:StringOf("regionName")
cStatus := oJson:StringOf("status")
cTimezone := oJson:StringOf("timezone")
cZip := oJson:StringOf("zip")

oHttp:destroy()
oJson:destroy()