I’m using graphics v1 compatibility mode and the scene is shown as an overlay.
Can you spot an error in my code? I have checked it against the example in docs. The only difference is that it has the newMapView outside createScene. I must, because it has a nav bar.
local storyboard=require("storyboard") local scene=storyboard.newScene() GEOADDR="Storgatan 1, Nassjo, Sweden" local tfaddr local myMap local function onbback(e) native.setKeyboardFocus( nil ) storyboard.hideOverlay("slideRight",400) return true end local function fieldHandler( getObj ) return function( event ) -- Use Lua closure in order to access the TextField object print( "TextField Object is: " .. tostring( getObj() ) ) if ( "began" == event.phase ) then --onfocus elseif ( "ended" == event.phase ) then --onblur elseif ( "submitted" == event.phase ) then --onenter native.setKeyboardFocus( nil ) end end -- "return function()" end local function onbaddr(e) GEOADDR=tostring( tfaddr.text) if GEOADDR:len()\>0 then print( "Text entered = " .. GEOADDR ) -- display the text entered myMap:requestLocation( GEOADDR, mapLocationHandler ) native.setKeyboardFocus( nil ) end return true end local function onbpinme(e) pinlat=91 --flag --pinlon=USERLON --'move' pin and zoom to it myMap:removeAllMarkers() local options={title="Selected location:",subtitle="Your phone's location"} myMap:addMarker(USERLAT,USERLON,options) myMap:setCenter(USERLAT,USERLON,true) myMap:nearestAddress(pinlat,pinlon,mapAddressHandler) return true end local function tfaddrHandler( event ) fieldHandler( function() return tfaddr end ) -- passes the text field object end ----------------------- local function mapLocationHandler( event ) if event.isError then local alert=native.showAlert("Google can't find "..GEOADDR,event.errorMessage,{"OK"}) else --'move' pin and zoom to it pinlat=event.latitude pinlon=event.longitude myMap:removeAllMarkers() local options={title="Selected location:",subtitle=GEOADDR} myMap:addMarker(pinlat,pinlon,options) myMap:setCenter(pinlat,pinlon,true) end end local function mapAddressHandler(e) if e.isError then tfaddr.text="Address not found" else tfaddr.text=e.city..", "..e.country end end local function getAddr() myMap:nearestAddress(pinlat,pinlon,mapAddressHandler) end local function callMap() local currloc=myMap:getUserLocation() if currloc then local currlat=currloc.latitude local currlon=currloc.longitude myMap:setCenter(currlat,currlon,true) --,1.5,1.5,true) myMap:nearestAddress(currentLatitude,currentLongitude) end end -- Called when the scene's view does not exist: function scene:createScene(event) print("map createScene") bg=display.newImageRect("assets/black16x16.png",CW2,CH2-50-T) --white bg bg.x=CW bg.y=T+(CH2-50-T)/2 self.view:insert(bg) --navbar inavbar=display.newImageRect("assets/navbarbg.png",320,64) inavbar.x=CW inavbar.y=64/2 --incl shadow self.view:insert(inavbar) bback=backbuttonarrow("Tillbaka","bback",onbback,14) self.view:insert(bback) tfaddr=native.newTextField( CW-106, 6, 172, 32 ) tfaddr:addEventListener( "userInput", tfaddrHandler ) tfaddr.isVisible=false baddr=imgbuttonr("search","baddr",CW2-40-4-44-6,0,44,44,onbaddr) self.view:insert(baddr) bpinme=imgbuttonr("gps","bpinme",CW2-40-4-0,0,44,44,onbpinme) self.view:insert(bpinme) --map-- myMap=native.newMapView(0,0,CW2,CH2-T-50) myMap.mapType="hybrid" -- other mapType options are "satellite" or "hybrid" -- The MapView is just another Corona display object,and can be moved or rotated,etc. myMap.x=CW myMap.y=(CH2-50-T)/2+T self.view:insert(myMap) --Runtime:addEventListener("mapAddress",mapAddressHandler) end -- Called immediately after scene has moved onscreen: function scene:enterScene(event) print("enterScene view"..tabindex) if pinlat\>90 then pinlat=mylat pinlon=mylon end local options={title="Selected location:",subtitle="Your phone's location"} myMap:addMarker(pinlat,pinlon,options) tfaddr.isVisible=true --myMap:setCenter(pinlat,pinlon,true) timer.performWithDelay(1000,callMap) -- get current location after 1 second --timer.performWithDelay(2500,getAddr) end -- Called when scene is about to move offscreen: function scene:exitScene(event) print("exitScene view"..tabindex) -- INSERT code here (e.g. stop timers,remove listeners,unload sounds,etc.) myMap:removeAllMarkers() end -- If scene's view is removed,scene:destroyScene() will be called just prior to: function scene:destroyScene(event) -- INSERT code here (e.g. remove listeners,remove widgets,save state variables,etc.) if myMap then --Runtime:removeEventListener("mapAddress",mapAddressHandler) myMap:removeSelf() end if tfaddr then tfaddr.isVisible=false tfaddr:removeEventListener("userInput",tfaddrHandler) end end scene:addEventListener("createScene",scene) -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener("enterScene",scene) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener("exitScene",scene) -- "exitScene" event is dispatched whenever before next scene's transition begins scene:addEventListener("destroyScene",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(). return scene
Let me know any hints to get this working rock solid. Using Corona 2076.