Created
September 12, 2018 02:45
-
-
Save agershun/778dc33995894585ae6ec0e1dd88ade5 to your computer and use it in GitHub Desktop.
Пример использования Naviaddress API на языке Lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----------------------------------------------------------------------------------------- | |
-- | |
-- main.lua | |
-- | |
----------------------------------------------------------------------------------------- | |
-- Your code here | |
local json = require( "json" ) | |
local cx = display.contentCenterX | |
local function handleResponse( event ) | |
if not event.isError then | |
local response = json.decode( event.response ) | |
local result = response.result | |
display.newText(result.container,cx,150) | |
display.newText(result.description,cx,200) | |
local function handleImage( event ) | |
if ( event.isError ) then | |
print( "Network error - download failed: ", event.response ) | |
elseif ( event.phase == "ended" ) then | |
myImage = display.newImage( event.response.filename, event.response.baseDirectory, cx, 350 ) | |
myImage:scale(0.2,0.2) | |
end | |
end | |
network.download(result.cover[1].image,"GET",handleImage,{},"image.jpg",system.TemporaryDirectory) | |
else | |
print( "Error!" ) | |
end | |
return | |
end | |
network.request( "https://staging-api.naviaddress.com/api/v1.5/Addresses/7/0022", "GET", handleResponse ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment