Is there a way to calculate longitude and latitude of current location without
using the native.newMap ?? i dont want to develop always a map view… [import]uid: 185094 topic_id: 33622 reply_id: 333622[/import]
Maybe I don’t understand your question, but why don’t you use the GPS functionality?
It returns latitude + longitude coordinates.
http://developer.coronalabs.com/content/gps
[import]uid: 106768 topic_id: 33622 reply_id: 133703[/import]
until yestarday i used this code for getting longitude/latitude…
[lua] myMap= native.newMapView( 0,50, display.contentWidth, display.contentHeight-99 );
myMap:addMarker( 37.119221,25.240471, { title=“Heliessa”, subtitle=“Heliessa Hotel in Paros Island” } )
myMap:setCenter( 37.119221,25.240471, true )
currentLocation = myMap:getUserLocation()
currentLatitude = currentLocation.latitude
currentLongitude = currentLocation.longitude
[import]uid: 185094 topic_id: 33622 reply_id: 133809[/import]
i tried to use the location events but there is an issue with them… My phylosophy is to calculate the coordinates of my current location before i call the map …
[lua]currentLatitude = 0
currentLongitude = 0
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
end
Runtime:addEventListener( “location”, locationHandler )
fromLoc = currentLatitude…","…currentLongitude
toLoc = “37.120119,25.234633”
url = “http://maps.google.com/maps?saddr="..fromLoc.."&daddr=”…toLoc
system.openURL( url ) [/lua]
The problem is that gps calculates the coordinates after the map is called… As a result current coordinates the first time are 0!!
Please Help guys!!
Is there a way to calculate the current location coordinates before i call a google map rooting?!
[import]uid: 185094 topic_id: 33622 reply_id: 133830[/import]
I’m not behind my macbook now but you should try something like:
currentLatitude = nil
currentLongitude = nil
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
if currentLatitude then
fromLoc = currentLatitude..","..currentLongitude
toLoc = "37.120119,25.234633"
url = "http://maps.google.com/maps?saddr="..fromLoc.."&daddr="..toLoc
system.openURL( url )
Runtime:removeEventListener( "location", locationHandler )
end
end
Runtime:addEventListener( "location", locationHandler )
[import]uid: 106768 topic_id: 33622 reply_id: 133845[/import]
well , i dont think this will work because the creation of rooting is a part of button touch event…
this is the whole code…
[lua]----------------------------------------------------------------------------------
– scenetemplate.lua
local storyboard = require( “storyboard” )
currentLatitude = 0
currentLongitude = 0
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
end
local scene = storyboard.newScene()
Runtime:addEventListener( “location”, locationHandler )
display.setStatusBar(display.DefaultStatusBar)
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
bg = display.newImageRect(“bg.png”,320,480)
bg.x = display.contentWidth/2
bg.y = display.contentHeight/2
Group1 = display.newGroup();
local nav = display.newImageRect(“navbar.png”,320,50)
nav:setReferencePoint(display.TopLeftReferencePoint)
nav.x=0
nav.y=0
Group1:insert(nav);
local home = display.newImageRect(“home.png”,35,35)
home:setReferencePoint(display.CenterReferencePoint)
home.x=25
home.y=nav.height/2
function home:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
storyboard.gotoScene(“menu”);
end
end
home:addEventListener( “touch”, home )
Group1:insert(home);
group:insert(bg);
group:insert(Group1);
local loc_map = display.newImageRect(“local_map.png”,320,380)
loc_map:setReferencePoint(display.TopLeftReferencePoint)
loc_map.x=0
loc_map.y=50
group:insert(loc_map);
Group2 = display.newGroup();
local nav2 = display.newImageRect(“navbar2.png”,320,50)
nav2:setReferencePoint(display.BottomLeftReferencePoint)
nav2.x=0
nav2.y=480
Group2:insert(nav2);
local live_map = display.newImageRect(“live_map.png”,60,40)
live_map:setReferencePoint(display.CenterReferencePoint)
Group2:insert(live_map);
live_map.x=80
live_map.y=nav2.y-nav2.height/2
local drive_me= display.newImageRect(“drive_me.png”,60,40)
drive_me:setReferencePoint(display.CenterReferencePoint)
Group2:insert(drive_me);
drive_me.x=live_map.x+80
drive_me.y=nav2.y-nav2.height/2
local standard_map = display.newImageRect(“standard_map_pr.png”,60,40)
standard_map:setReferencePoint(display.CenterReferencePoint)
Group2:insert(standard_map);
standard_map.x=drive_me.x+80
standard_map.y=nav2.y-nav2.height/2
group:insert(Group2);
–myMap2= native.newMapView( 0,50, display.contentWidth, display.contentHeight-100 );
–myMap2.isVisible = false
function live_map:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
storyboard.gotoScene(“topothesia”);
end
end
live_map:addEventListener( “touch”, live_map )
function drive_me:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
– local currentLocation = myMap2:getUserLocation()
–local currentLatitude = currentLocation.latitude
–local currentLongitude = currentLocation.longitude
fromLoc = currentLatitude…","…currentLongitude
toLoc = “37.120119,25.234633”
url = “http://maps.google.com/maps?saddr="..fromLoc.."&daddr=”…toLoc
system.openURL( url )
end
end
drive_me:addEventListener( “touch”, drive_me )
– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
–myMap2:removeSelf()
storyboard.removeScene( “standard_topothesia” )
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
end
– END OF YOUR IMPLEMENTATION
– “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 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 [import]uid: 185094 topic_id: 33622 reply_id: 133864[/import]
I saw something from a corona proggie a couple months ago that implied that (at least for android) GPS functionality was linked to mapViews. In that case (You could search for the “Android Battery Issue” blog post I think), they said that when the app was suspended, the only way to disable the GPS was to destroy the apps existing mapview (until they fixed the suspend bug)… Implying there is a systemic connection between GPS location data and mapViews…
As far as I know this was only on Android though.
I’m doing a variety of things with multiple mapviews on both iOS and Android, and don’t have this particular issue, but that’s likely due to how I instantiate/use maps… In my case, I create a mapView (and instantiate the locationhandler) very early in the app launch process, however, I set the mapView to invisible (it’s native/appears on top of things, and I have other things I want to appear during launch).
Perhaps you can create the mapView, but set it isVisible = false while you wait for GPS coordinates? [import]uid: 79933 topic_id: 33622 reply_id: 133865[/import]
Maybe I don’t understand your question, but why don’t you use the GPS functionality?
It returns latitude + longitude coordinates.
http://developer.coronalabs.com/content/gps
[import]uid: 106768 topic_id: 33622 reply_id: 133703[/import]
yes i had already done that…
[lua] --myMap2= native.newMapView( 0,50, display.contentWidth, display.contentHeight-100 );
–myMap2.isVisible = false[/lua]
but this created some bug and sometimes my app crashed…
i think corona has many problems with android… there are so many bugs… [import]uid: 185094 topic_id: 33622 reply_id: 133999[/import]
until yestarday i used this code for getting longitude/latitude…
[lua] myMap= native.newMapView( 0,50, display.contentWidth, display.contentHeight-99 );
myMap:addMarker( 37.119221,25.240471, { title=“Heliessa”, subtitle=“Heliessa Hotel in Paros Island” } )
myMap:setCenter( 37.119221,25.240471, true )
currentLocation = myMap:getUserLocation()
currentLatitude = currentLocation.latitude
currentLongitude = currentLocation.longitude
[import]uid: 185094 topic_id: 33622 reply_id: 133809[/import]
i tried to use the location events but there is an issue with them… My phylosophy is to calculate the coordinates of my current location before i call the map …
[lua]currentLatitude = 0
currentLongitude = 0
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
end
Runtime:addEventListener( “location”, locationHandler )
fromLoc = currentLatitude…","…currentLongitude
toLoc = “37.120119,25.234633”
url = “http://maps.google.com/maps?saddr="..fromLoc.."&daddr=”…toLoc
system.openURL( url ) [/lua]
The problem is that gps calculates the coordinates after the map is called… As a result current coordinates the first time are 0!!
Please Help guys!!
Is there a way to calculate the current location coordinates before i call a google map rooting?!
[import]uid: 185094 topic_id: 33622 reply_id: 133830[/import]
I’m not behind my macbook now but you should try something like:
currentLatitude = nil
currentLongitude = nil
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
if currentLatitude then
fromLoc = currentLatitude..","..currentLongitude
toLoc = "37.120119,25.234633"
url = "http://maps.google.com/maps?saddr="..fromLoc.."&daddr="..toLoc
system.openURL( url )
Runtime:removeEventListener( "location", locationHandler )
end
end
Runtime:addEventListener( "location", locationHandler )
[import]uid: 106768 topic_id: 33622 reply_id: 133845[/import]
well , i dont think this will work because the creation of rooting is a part of button touch event…
this is the whole code…
[lua]----------------------------------------------------------------------------------
– scenetemplate.lua
local storyboard = require( “storyboard” )
currentLatitude = 0
currentLongitude = 0
function locationHandler( event )
currentLatitude = event.latitude
currentLongitude = event.longitude
end
local scene = storyboard.newScene()
Runtime:addEventListener( “location”, locationHandler )
display.setStatusBar(display.DefaultStatusBar)
–
– NOTE:
– Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
– BEGINNING OF YOUR IMPLEMENTATION
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
bg = display.newImageRect(“bg.png”,320,480)
bg.x = display.contentWidth/2
bg.y = display.contentHeight/2
Group1 = display.newGroup();
local nav = display.newImageRect(“navbar.png”,320,50)
nav:setReferencePoint(display.TopLeftReferencePoint)
nav.x=0
nav.y=0
Group1:insert(nav);
local home = display.newImageRect(“home.png”,35,35)
home:setReferencePoint(display.CenterReferencePoint)
home.x=25
home.y=nav.height/2
function home:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
storyboard.gotoScene(“menu”);
end
end
home:addEventListener( “touch”, home )
Group1:insert(home);
group:insert(bg);
group:insert(Group1);
local loc_map = display.newImageRect(“local_map.png”,320,380)
loc_map:setReferencePoint(display.TopLeftReferencePoint)
loc_map.x=0
loc_map.y=50
group:insert(loc_map);
Group2 = display.newGroup();
local nav2 = display.newImageRect(“navbar2.png”,320,50)
nav2:setReferencePoint(display.BottomLeftReferencePoint)
nav2.x=0
nav2.y=480
Group2:insert(nav2);
local live_map = display.newImageRect(“live_map.png”,60,40)
live_map:setReferencePoint(display.CenterReferencePoint)
Group2:insert(live_map);
live_map.x=80
live_map.y=nav2.y-nav2.height/2
local drive_me= display.newImageRect(“drive_me.png”,60,40)
drive_me:setReferencePoint(display.CenterReferencePoint)
Group2:insert(drive_me);
drive_me.x=live_map.x+80
drive_me.y=nav2.y-nav2.height/2
local standard_map = display.newImageRect(“standard_map_pr.png”,60,40)
standard_map:setReferencePoint(display.CenterReferencePoint)
Group2:insert(standard_map);
standard_map.x=drive_me.x+80
standard_map.y=nav2.y-nav2.height/2
group:insert(Group2);
–myMap2= native.newMapView( 0,50, display.contentWidth, display.contentHeight-100 );
–myMap2.isVisible = false
function live_map:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
storyboard.gotoScene(“topothesia”);
end
end
live_map:addEventListener( “touch”, live_map )
function drive_me:touch(e)
if (e.phase==“began”) then
display.getCurrentStage():setFocus(e.target,e.id);
elseif(e.phase==“moved”) then
print(“moved”);
elseif(e.phase==“ended”) then
display.getCurrentStage():setFocus(e.target,nil);
– local currentLocation = myMap2:getUserLocation()
–local currentLatitude = currentLocation.latitude
–local currentLongitude = currentLocation.longitude
fromLoc = currentLatitude…","…currentLongitude
toLoc = “37.120119,25.234633”
url = “http://maps.google.com/maps?saddr="..fromLoc.."&daddr=”…toLoc
system.openURL( url )
end
end
drive_me:addEventListener( “touch”, drive_me )
– CREATE display objects and add them to ‘group’ here.
– Example use-case: Restore ‘group’ from previously saved state.
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
–myMap2:removeSelf()
storyboard.removeScene( “standard_topothesia” )
– INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.)
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
local group = self.view
– INSERT code here (e.g. remove listeners, widgets, save state, etc.)
end
– END OF YOUR IMPLEMENTATION
– “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 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 [import]uid: 185094 topic_id: 33622 reply_id: 133864[/import]
I saw something from a corona proggie a couple months ago that implied that (at least for android) GPS functionality was linked to mapViews. In that case (You could search for the “Android Battery Issue” blog post I think), they said that when the app was suspended, the only way to disable the GPS was to destroy the apps existing mapview (until they fixed the suspend bug)… Implying there is a systemic connection between GPS location data and mapViews…
As far as I know this was only on Android though.
I’m doing a variety of things with multiple mapviews on both iOS and Android, and don’t have this particular issue, but that’s likely due to how I instantiate/use maps… In my case, I create a mapView (and instantiate the locationhandler) very early in the app launch process, however, I set the mapView to invisible (it’s native/appears on top of things, and I have other things I want to appear during launch).
Perhaps you can create the mapView, but set it isVisible = false while you wait for GPS coordinates? [import]uid: 79933 topic_id: 33622 reply_id: 133865[/import]
yes i had already done that…
[lua] --myMap2= native.newMapView( 0,50, display.contentWidth, display.contentHeight-100 );
–myMap2.isVisible = false[/lua]
but this created some bug and sometimes my app crashed…
i think corona has many problems with android… there are so many bugs… [import]uid: 185094 topic_id: 33622 reply_id: 133999[/import]