Sample code for 30+ languages & platforms
Visual FoxPro

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

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcJsonStr
LOCAL loJson
LOCAL lcAs
LOCAL lcCity
LOCAL lcCountry
LOCAL lcCountryCode
LOCAL lcIsp
LOCAL lcLat
LOCAL lcLon
LOCAL lcOrg
LOCAL lcQuery
LOCAL lcRegion
LOCAL lcRegionName
LOCAL lcStatus
LOCAL lcTimezone
LOCAL lcZip

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

* {
*   "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"
* }

lcAs = loJson.StringOf("as")
lcCity = loJson.StringOf("city")
lcCountry = loJson.StringOf("country")
lcCountryCode = loJson.StringOf("countryCode")
lcIsp = loJson.StringOf("isp")
lcLat = loJson.StringOf("lat")
lcLon = loJson.StringOf("lon")
lcOrg = loJson.StringOf("org")
lcQuery = loJson.StringOf("query")
lcRegion = loJson.StringOf("region")
lcRegionName = loJson.StringOf("regionName")
lcStatus = loJson.StringOf("status")
lcTimezone = loJson.StringOf("timezone")
lcZip = loJson.StringOf("zip")

RELEASE loHttp
RELEASE loJson