Lua
Lua
Azure Maps Get Search Address
See more Azure Maps Examples
Get information for a given address.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()
http.accept = "application/json"
local url = "https://atlas.microsoft.com/search/address/{$format}?subscription-key=[subscription-key]&api-version=1.0&query={$query}"
http:set_url_var("format", "json")
http:set_url_var("query", "15127 NE 24th Street, Redmond, WA 98052")
local strResp = http:quick_get_str(url)
if not http.last_method_success then
print(http.last_error_text)
return
end
print("Response Status Code: " .. http.last_status)
local jsonResponse = chilkat.JsonObject.new()
jsonResponse:load(strResp)
jsonResponse.emit_compact = false
print(jsonResponse:emit())
if http.last_status ~= 200 then
print("Failed.")
return
end
-- Sample output...
-- (See the parsing code below..)
--
-- Use this online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON
-- {
-- "summary": {
-- "query": "15127 NE 24th Street, Redmond, WA 98052",
-- "queryType": "NON_NEAR",
-- "queryTime": 58,
-- "numResults": 1,
-- "offset": 0,
-- "totalResults": 1,
-- "fuzzyLevel": 1
-- },
-- "results": [
-- {
-- "type": "Point Address",
-- "id": "US/PAD/p0/19173426",
-- "score": 14.51,
-- "address": {
-- "streetNumber": "15127",
-- "streetName": "NE 24th St",
-- "municipalitySubdivision": "Redmond",
-- "municipality": "Redmond, Adelaide, Ames Lake, Avondale, Earlmount",
-- "countrySecondarySubdivision": "King",
-- "countryTertiarySubdivision": "Seattle East",
-- "countrySubdivision": "WA",
-- "postalCode": "98052",
-- "extendedPostalCode": "980525544",
-- "countryCode": "US",
-- "country": "United States Of America",
-- "countryCodeISO3": "USA",
-- "freeformAddress": "15127 NE 24th St, Redmond, WA 980525544",
-- "countrySubdivisionName": "Washington"
-- },
-- "position": {
-- "lat": 47.6308,
-- "lon": -122.1385
-- },
-- "viewport": {
-- "topLeftPoint": {
-- "lat": 47.6317,
-- "lon": -122.13983
-- },
-- "btmRightPoint": {
-- "lat": 47.6299,
-- "lon": -122.13717
-- }
-- },
-- "entryPoints": [
-- {
-- "type": "main",
-- "position": {
-- "lat": 47.6315,
-- "lon": -122.13852
-- }
-- }
-- ]
-- }
-- ]
-- }
--
local v_type = ""
local id = ""
local score = ""
local addressStreetNumber = ""
local addressStreetName = ""
local addressMunicipalitySubdivision = ""
local addressMunicipality = ""
local addressCountrySecondarySubdivision = ""
local addressCountryTertiarySubdivision = ""
local addressCountrySubdivision = ""
local addressPostalCode = ""
local addressExtendedPostalCode = ""
local addressCountryCode = ""
local addressCountry = ""
local addressCountryCodeISO3 = ""
local addressFreeformAddress = ""
local addressCountrySubdivisionName = ""
local positionLat = ""
local positionLon = ""
local viewportTopLeftPointLat = ""
local viewportTopLeftPointLon = ""
local viewportBtmRightPointLat = ""
local viewportBtmRightPointLon = ""
local j = 0
local count_j = 0
local summaryQuery = jsonResponse:string_of("summary.query")
local summaryQueryType = jsonResponse:string_of("summary.queryType")
local summaryQueryTime = jsonResponse:int_of("summary.queryTime")
local summaryNumResults = jsonResponse:int_of("summary.numResults")
local summaryOffset = jsonResponse:int_of("summary.offset")
local summaryTotalResults = jsonResponse:int_of("summary.totalResults")
local summaryFuzzyLevel = jsonResponse:int_of("summary.fuzzyLevel")
local i = 0
local count_i = jsonResponse:size_of_array("results")
while i < count_i do
jsonResponse.i = i
v_type = jsonResponse:string_of("results[i].type")
id = jsonResponse:string_of("results[i].id")
score = jsonResponse:string_of("results[i].score")
addressStreetNumber = jsonResponse:string_of("results[i].address.streetNumber")
addressStreetName = jsonResponse:string_of("results[i].address.streetName")
addressMunicipalitySubdivision = jsonResponse:string_of("results[i].address.municipalitySubdivision")
addressMunicipality = jsonResponse:string_of("results[i].address.municipality")
addressCountrySecondarySubdivision = jsonResponse:string_of("results[i].address.countrySecondarySubdivision")
addressCountryTertiarySubdivision = jsonResponse:string_of("results[i].address.countryTertiarySubdivision")
addressCountrySubdivision = jsonResponse:string_of("results[i].address.countrySubdivision")
addressPostalCode = jsonResponse:string_of("results[i].address.postalCode")
addressExtendedPostalCode = jsonResponse:string_of("results[i].address.extendedPostalCode")
addressCountryCode = jsonResponse:string_of("results[i].address.countryCode")
addressCountry = jsonResponse:string_of("results[i].address.country")
addressCountryCodeISO3 = jsonResponse:string_of("results[i].address.countryCodeISO3")
addressFreeformAddress = jsonResponse:string_of("results[i].address.freeformAddress")
addressCountrySubdivisionName = jsonResponse:string_of("results[i].address.countrySubdivisionName")
positionLat = jsonResponse:string_of("results[i].position.lat")
positionLon = jsonResponse:string_of("results[i].position.lon")
viewportTopLeftPointLat = jsonResponse:string_of("results[i].viewport.topLeftPoint.lat")
viewportTopLeftPointLon = jsonResponse:string_of("results[i].viewport.topLeftPoint.lon")
viewportBtmRightPointLat = jsonResponse:string_of("results[i].viewport.btmRightPoint.lat")
viewportBtmRightPointLon = jsonResponse:string_of("results[i].viewport.btmRightPoint.lon")
j = 0
count_j = jsonResponse:size_of_array("results[i].entryPoints")
while j < count_j do
jsonResponse.j = j
v_type = jsonResponse:string_of("results[i].entryPoints[j].type")
positionLat = jsonResponse:string_of("results[i].entryPoints[j].position.lat")
positionLon = jsonResponse:string_of("results[i].entryPoints[j].position.lon")
j = j + 1
end
i = i + 1
end