Lua
Lua
geo.ipify.org IPv4 Geolocation Lookup
See more Geolocation Examples
Demonstrates how to lookup Geolocation data for an IPv4 address using the geo.ipify.org REST API.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- Lookup an IPv4 address: 8.8.8.8
local jsonStr = http:quick_get_str("https://geo.ipify.org/api/v1?apiKey=API_KEY&ipAddress=8.8.8.8")
if not http.last_method_success then
print(http.last_error_text)
return
end
local json = chilkat.JsonObject.new()
json.emit_compact = false
local success = json:load(jsonStr)
print(json:emit())
-- Sample output:
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
-- {
-- "ip": "8.8.8.8",
-- "location": {
-- "country": "IT",
-- "region": "Lombardy",
-- "city": "Milan",
-- "lat": 45.4707,
-- "lng": 9.1889,
-- "postalCode": "20147",
-- "timezone": "+02:00"
-- }
-- }
local ip = json:string_of("ip")
local locationCountry = json:string_of("location.country")
local locationRegion = json:string_of("location.region")
local locationCity = json:string_of("location.city")
local locationLat = json:string_of("location.lat")
local locationLng = json:string_of("location.lng")
local locationPostalCode = json:string_of("location.postalCode")
local locationTimezone = json:string_of("location.timezone")