Hi, I am trying to put a location event in a tab but it seems i cant get the value of the location on a phone, it works fine on the simulator but it seems to that the location event is disregarded entirely.
Supposedly the text should be put in the variable loc and it is then displayed by the title variable
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
local loc = "test"
local function locationHandler( event )
if event.errorCode then
loc = event.errorMessage
else
local clat = string.format( '%.5f', event.latitude )
local clon = string.format( '%.5f', event.longitude )
local elat = 14.633365
local elon = 121.05646
loc1 = "Location \n"..clat..", "..clon.."\n\n".."Event Location \n"..elat..", "..elon.."\n Distance: "..distance.."\n\n OK\n\n"
loc = loc1
end
end
-- Called when the scene's view does not exist:
function scene:createScene( event )
local group = self.view
-- create a white background to fill screen
local bg = display.newRect( 0, 0, display.contentWidth, display.contentHeight )
bg:setFillColor( 255 ) -- white
-- create some text
local title = display.newRetinaText(loc, 0, 0, native.systemFont, 20 )
title:setTextColor( 0 ) -- black
title:setReferencePoint( display.CenterReferencePoint )
title.x = display.contentWidth \* 0.5
title.y = 170
-- all objects must be added to group (e.g. self.view)
group:insert( bg )
group:insert( title )
end
-- Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
-- Do nothing
end
-- Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
-- INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
-- If scene's view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
-- INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)
end
-----------------------------------------------------------------------------------------
-- END OF YOUR IMPLEMENTATION
-----------------------------------------------------------------------------------------
-- Activate location listener
Runtime:addEventListener( "location", locationHandler )
-- "createScene" event is dispatched if scene's view does not exist
scene:addEventListener( "createScene", scene )
-- "enterScene" event is dispatched whenever scene transition has finished
scene:addEventListener( "enterScene", scene )
-- "exitScene" event is dispatched whenever before next scene's transition begins
scene:addEventListener( "exitScene", scene )
-- "destroyScene" event is dispatched before view is unloaded, which can be
-- automatically unloaded in low memory situations, or explicitly via a call to
-- storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( "destroyScene", scene )
-----------------------------------------------------------------------------------------
return scene
Thanks [import]uid: 203071 topic_id: 35723 reply_id: 335723[/import]