Hi, I’m hoping for your experience to fix my error.
What I want to achieve is this:
At phone start, phone locates lattitude and longitude, these then get concatenated into a variable, which is then used later in the code to construct a url.
I am so close but have hit a wall. A code snippet below:
local latlongdisplay = display.newText( "-", 100, 50, native.systemFont, 16 ) locationHandler = function( event ) if ( event.errorCode ) then native.showAlert( "GPS Location Error", event.errorMessage, {"OK"} ) print( "Location error: " .. tostring( event.errorMessage ) ) else local latlongtext = string.format( '%.4f', event.latitude ) .. "," .. string.format( '%.4f', event.longitude ) latlongdisplay.text = latlongtext end return latlongtext end Runtime:addEventListener( "location", locationHandler ) if latlongtext == nil then print( " it was nil" ) else print( "it was: " .. latlongtext ) end
so… this works fine to populate the display.newText object, and I see it on screen… however, the actual local variable of latlongtext remains nil.
Can someone please advise how I reliably get the value of latlongtext OUT of the function, so I can use it elsewhere.
ps, I know it’s a local variable inside the if/then clause, but I’d prefer to not have to use a global variable, when there is likely a better method.
thanks all