DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
String sJsonStr
Handle hoJson
String sIp
String sV_type
String sContinent_code
String sContinent_name
String sCountry_code
String sCountry_name
String sRegion_code
String sRegion_name
String sCity
String sZip
String sLatitude
String sLongitude
String sLocationGeoname_id
String sLocationCapital
String sLocationCountry_flag
String sLocationCountry_flag_emoji
String sLocationCountry_flag_emoji_unicode
String sLocationCalling_code
Boolean iLocationIs_eu
Integer i
Integer iCount_i
String sCode
String sName
String sNative
String sTemp1
Boolean bTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Lookup an IPv4 address: 149.250.207.170 (this was a randomly chosen address)
Get ComQuickGetStr Of hoHttp "http://api.ipstack.com/149.250.207.170?access_key=YOUR_ACCESS_KEY" To sJsonStr
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Set ComEmitCompact Of hoJson To False
Get ComLoad Of hoJson sJsonStr To iSuccess
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// 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
// }
// }
Get ComStringOf Of hoJson "ip" To sIp
Get ComStringOf Of hoJson "type" To sV_type
Get ComStringOf Of hoJson "continent_code" To sContinent_code
Get ComStringOf Of hoJson "continent_name" To sContinent_name
Get ComStringOf Of hoJson "country_code" To sCountry_code
Get ComStringOf Of hoJson "country_name" To sCountry_name
Get ComStringOf Of hoJson "region_code" To sRegion_code
Get ComStringOf Of hoJson "region_name" To sRegion_name
Get ComStringOf Of hoJson "city" To sCity
Get ComStringOf Of hoJson "zip" To sZip
Get ComStringOf Of hoJson "latitude" To sLatitude
Get ComStringOf Of hoJson "longitude" To sLongitude
Get ComStringOf Of hoJson "location.geoname_id" To sLocationGeoname_id
Get ComStringOf Of hoJson "location.capital" To sLocationCapital
Get ComStringOf Of hoJson "location.country_flag" To sLocationCountry_flag
Get ComStringOf Of hoJson "location.country_flag_emoji" To sLocationCountry_flag_emoji
Get ComStringOf Of hoJson "location.country_flag_emoji_unicode" To sLocationCountry_flag_emoji_unicode
Get ComStringOf Of hoJson "location.calling_code" To sLocationCalling_code
Get ComBoolOf Of hoJson "location.is_eu" To iLocationIs_eu
Move 0 To i
Get ComSizeOfArray Of hoJson "location.languages" To iCount_i
While (i < iCount_i)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "location.languages[i].code" To sCode
Get ComStringOf Of hoJson "location.languages[i].name" To sName
Get ComStringOf Of hoJson "location.languages[i].native" To sNative
Move (i + 1) To i
Loop
End_Procedure