Sample code for 30+ languages & platforms
Visual FoxPro

MaxMind IPv4 Geolocation Lookup

See more Geolocation Examples

Demonstrates how to lookup Geolocation data for an IPv4 address using the MaxMind GeoIP2 Precision Web Service.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL lcJsonStr
LOCAL loJson
LOCAL lcContinentCode
LOCAL lnContinentGeoname_id
LOCAL lcContinentNamesJa
LOCAL lcContinentNamesPt_BR
LOCAL lcContinentNamesRu
LOCAL lcContinentNamesZh_CN
LOCAL lcContinentNamesDe
LOCAL lcContinentNamesEn
LOCAL lcContinentNamesEs
LOCAL lcContinentNamesFr
LOCAL lnCountryIs_in_european_union
LOCAL lcCountryIso_code
LOCAL lnCountryGeoname_id
LOCAL lcCountryNamesFr
LOCAL lcCountryNamesJa
LOCAL lcCountryNamesPt_BR
LOCAL lcCountryNamesRu
LOCAL lcCountryNamesZh_CN
LOCAL lcCountryNamesDe
LOCAL lcCountryNamesEn
LOCAL lcCountryNamesEs
LOCAL lnMaxmindQueries_remaining
LOCAL lnRegistered_countryIs_in_european_union
LOCAL lcRegistered_countryIso_code
LOCAL lnRegistered_countryGeoname_id
LOCAL lcRegistered_countryNamesEs
LOCAL lcRegistered_countryNamesFr
LOCAL lcRegistered_countryNamesJa
LOCAL lcRegistered_countryNamesPt_BR
LOCAL lcRegistered_countryNamesRu
LOCAL lcRegistered_countryNamesZh_CN
LOCAL lcRegistered_countryNamesDe
LOCAL lcRegistered_countryNamesEn
LOCAL lcTraitsIp_address

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

loHttp.Login = "MAXMIND_ACCOUNT_ID"
loHttp.Password = "MAXMIND_LICENSE_KEY"
loHttp.Accept = "application/json"

* Lookup an IPv4 address: 149.250.207.170  (this was a randomly chosen address)
lcJsonStr = loHttp.QuickGetStr("https://geoip.maxmind.com/geoip/v2.1/country/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

* {
*   "continent": {
*     "code": "EU",
*     "geoname_id": 6255148,
*     "names": {
*       "ja": "?????",
*       "pt-BR": "Europa",
*       "ru": "??????",
*       "zh-CN": "??",
*       "de": "Europa",
*       "en": "Europe",
*       "es": "Europa",
*       "fr": "Europe"
*     }
*   },
*   "country": {
*     "is_in_european_union": true,
*     "iso_code": "DE",
*     "geoname_id": 2921044,
*     "names": {
*       "fr": "Allemagne",
*       "ja": "????????",
*       "pt-BR": "Alemanha",
*       "ru": "????????",
*       "zh-CN": "??",
*       "de": "Deutschland",
*       "en": "Germany",
*       "es": "Alemania"
*     }
*   },
*   "maxmind": {
*     "queries_remaining": 49999
*   },
*   "registered_country": {
*     "is_in_european_union": true,
*     "iso_code": "DE",
*     "geoname_id": 2921044,
*     "names": {
*       "es": "Alemania",
*       "fr": "Allemagne",
*       "ja": "????????",
*       "pt-BR": "Alemanha",
*       "ru": "????????",
*       "zh-CN": "??",
*       "de": "Deutschland",
*       "en": "Germany"
*     }
*   },
*   "traits": {
*     "ip_address": "149.250.207.170"
*   }
* }
* 
* 

lcContinentCode = loJson.StringOf("continent.code")
lnContinentGeoname_id = loJson.IntOf("continent.geoname_id")
lcContinentNamesJa = loJson.StringOf("continent.names.ja")
lcContinentNamesPt_BR = loJson.StringOf("continent.names.pt-BR")
lcContinentNamesRu = loJson.StringOf("continent.names.ru")
lcContinentNamesZh_CN = loJson.StringOf("continent.names.zh-CN")
lcContinentNamesDe = loJson.StringOf("continent.names.de")
lcContinentNamesEn = loJson.StringOf("continent.names.en")
lcContinentNamesEs = loJson.StringOf("continent.names.es")
lcContinentNamesFr = loJson.StringOf("continent.names.fr")
lnCountryIs_in_european_union = loJson.BoolOf("country.is_in_european_union")
lcCountryIso_code = loJson.StringOf("country.iso_code")
lnCountryGeoname_id = loJson.IntOf("country.geoname_id")
lcCountryNamesFr = loJson.StringOf("country.names.fr")
lcCountryNamesJa = loJson.StringOf("country.names.ja")
lcCountryNamesPt_BR = loJson.StringOf("country.names.pt-BR")
lcCountryNamesRu = loJson.StringOf("country.names.ru")
lcCountryNamesZh_CN = loJson.StringOf("country.names.zh-CN")
lcCountryNamesDe = loJson.StringOf("country.names.de")
lcCountryNamesEn = loJson.StringOf("country.names.en")
lcCountryNamesEs = loJson.StringOf("country.names.es")
lnMaxmindQueries_remaining = loJson.IntOf("maxmind.queries_remaining")
lnRegistered_countryIs_in_european_union = loJson.BoolOf("registered_country.is_in_european_union")
lcRegistered_countryIso_code = loJson.StringOf("registered_country.iso_code")
lnRegistered_countryGeoname_id = loJson.IntOf("registered_country.geoname_id")
lcRegistered_countryNamesEs = loJson.StringOf("registered_country.names.es")
lcRegistered_countryNamesFr = loJson.StringOf("registered_country.names.fr")
lcRegistered_countryNamesJa = loJson.StringOf("registered_country.names.ja")
lcRegistered_countryNamesPt_BR = loJson.StringOf("registered_country.names.pt-BR")
lcRegistered_countryNamesRu = loJson.StringOf("registered_country.names.ru")
lcRegistered_countryNamesZh_CN = loJson.StringOf("registered_country.names.zh-CN")
lcRegistered_countryNamesDe = loJson.StringOf("registered_country.names.de")
lcRegistered_countryNamesEn = loJson.StringOf("registered_country.names.en")
lcTraitsIp_address = loJson.StringOf("traits.ip_address")

RELEASE loHttp
RELEASE loJson