Lianja
Lianja
ipstack.com IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the ipstack.com REST API.Chilkat Lianja Downloads
llSuccess = .F.
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
lcJsonStr = loHttp.QuickGetStr("http://api.ipstack.com/149.250.207.170?access_key=YOUR_ACCESS_KEY")
if (loHttp.LastMethodSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
return
endif
loJson = createobject("CkJsonObject")
loJson.EmitCompact = .F.
llSuccess = loJson.Load(lcJsonStr)
? loJson.Emit()
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "ip": "149.250.207.170",
// "type": "ipv4",
// "continent_code": "EU",
// "continent_name": "Europe",
// "country_code": "DE",
// "country_name": "Germany",
// "region_code": null,
// "region_name": null,
// "city": null,
// "zip": null,
// "latitude": 51.2993,
// "longitude": 9.491,
// "location": {
// "geoname_id": null,
// "capital": "Berlin",
// "languages": [
// {
// "code": "de",
// "name": "German",
// "native": "Deutsch"
// }
// ],
// "country_flag": "http:\/\/assets.ipstack.com\/flags\/de.svg",
// "country_flag_emoji": "\ud83c\udde9\ud83c\uddea",
// "country_flag_emoji_unicode": "U+1F1E9 U+1F1EA",
// "calling_code": "49",
// "is_eu": true
// }
// }
lcIp = loJson.StringOf("ip")
lcV_type = loJson.StringOf("type")
lcContinent_code = loJson.StringOf("continent_code")
lcContinent_name = loJson.StringOf("continent_name")
lcCountry_code = loJson.StringOf("country_code")
lcCountry_name = loJson.StringOf("country_name")
lcRegion_code = loJson.StringOf("region_code")
lcRegion_name = loJson.StringOf("region_name")
lcCity = loJson.StringOf("city")
lcZip = loJson.StringOf("zip")
lcLatitude = loJson.StringOf("latitude")
lcLongitude = loJson.StringOf("longitude")
lcLocationGeoname_id = loJson.StringOf("location.geoname_id")
lcLocationCapital = loJson.StringOf("location.capital")
lcLocationCountry_flag = loJson.StringOf("location.country_flag")
lcLocationCountry_flag_emoji = loJson.StringOf("location.country_flag_emoji")
lcLocationCountry_flag_emoji_unicode = loJson.StringOf("location.country_flag_emoji_unicode")
lcLocationCalling_code = loJson.StringOf("location.calling_code")
llLocationIs_eu = loJson.BoolOf("location.is_eu")
i = 0
lnCount_i = loJson.SizeOfArray("location.languages")
do while i < lnCount_i
loJson.I = i
lcCode = loJson.StringOf("location.languages[i].code")
lcName = loJson.StringOf("location.languages[i].name")
lcNative = loJson.StringOf("location.languages[i].native")
i = i + 1
enddo
release loHttp
release loJson