Sample code for 30+ languages & platforms
Visual FoxPro

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 Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcJsonStr
LOCAL loJson
LOCAL lcIp
LOCAL lcV_type
LOCAL lcContinent_code
LOCAL lcContinent_name
LOCAL lcCountry_code
LOCAL lcCountry_name
LOCAL lcRegion_code
LOCAL lcRegion_name
LOCAL lcCity
LOCAL lcZip
LOCAL lcLatitude
LOCAL lcLongitude
LOCAL lcLocationGeoname_id
LOCAL lcLocationCapital
LOCAL lcLocationCountry_flag
LOCAL lcLocationCountry_flag_emoji
LOCAL lcLocationCountry_flag_emoji_unicode
LOCAL lcLocationCalling_code
LOCAL lnLocationIs_eu
LOCAL i
LOCAL lnCount_i
LOCAL lcCode
LOCAL lcName
LOCAL lcNative

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

* 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 = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    CANCEL
ENDIF

loJson = CreateObject('Chilkat.JsonObject')
loJson.EmitCompact = 0
lnSuccess = 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")
lnLocationIs_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