Sample code for 30+ languages & platforms
Xbase++

geo.ipify.org IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the geo.ipify.org REST API.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oHttp
LOCAL cJsonStr
LOCAL oJson
LOCAL cIp
LOCAL cLocationCountry
LOCAL cLocationRegion
LOCAL cLocationCity
LOCAL cLocationLat
LOCAL cLocationLng
LOCAL cLocationPostalCode
LOCAL cLocationTimezone

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: 8.8.8.8
cJsonStr := oHttp:QuickGetStr("https://geo.ipify.org/api/v1?apiKey=API_KEY&ipAddress=8.8.8.8")
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": "8.8.8.8",
//    "location": {
//      "country": "IT",
//      "region": "Lombardy",
//      "city": "Milan",
//      "lat": 45.4707,
//      "lng": 9.1889,
//      "postalCode": "20147",
//      "timezone": "+02:00"
//    }
//  }

cIp := oJson:StringOf("ip")
cLocationCountry := oJson:StringOf("location.country")
cLocationRegion := oJson:StringOf("location.region")
cLocationCity := oJson:StringOf("location.city")
cLocationLat := oJson:StringOf("location.lat")
cLocationLng := oJson:StringOf("location.lng")
cLocationPostalCode := oJson:StringOf("location.postalCode")
cLocationTimezone := oJson:StringOf("location.timezone")

oHttp:destroy()
oJson:destroy()