Pretty basic MapView crashes on Android, glitches a little on Iphone

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.

Managed to film the crash messages and pause the frame. The lesson learned was that handlers must be at the top of the source, so that functions that use them don’t get a nil for the handler argument. In general you should define functions in load->use order.

You can store it in a variable to avoid this, and I suspect if they hadn’t been local functions it would also have worked.

It crashed with and without v1 compatbility mode and now works in both, so that rules out any problems with build 2076.

There seems to be a problem with re-adding markers with 2076, though. The first time a marker is added, it works properly. The following times a marker is added, that marker’s coordinate system vs. the map scale is out of wack - as I zoom out, the marker is moved to another part of the country or outside the view…

 

local function onbpinme(event)     myMap:setCenter(USERLAT,USERLON,true)     myMap:nearestAddress(USERLAT,USERLON,mapAddressHandler)             myMap:removeAllMarkers()     local options={title="Selected location:",subtitle="Your phone's location"}     myMap:addMarker(USERLAT,USERLON,options)     return true     end  

I will be very happy if you can locate any error in my code, or a workaround, such as “moving” a marker instead of deleting and re-adding it.

This happens with or without v1 compatibility mode. Help!!

Saving the marker ID and removing just that if it’s set, doesn’t fix it. (I’m not editing my previous post since editing posts breaks the code formatting.)

Edit: I’ve now put the map creation code at the top of the source outside any function, instead of in createScene, and I don’t self.view:insert() it anymore. I also don’t removeSelf() on exit. Still doesn’t work for the subsequent removeMarker()+addMarker().

If I don’t use removeAllMarkers() or removeMarker() at all, it works. But I’d need some way of hiding them then, or access some table that I can empty manually with some magic code.

Edit 2: Also tried using gotoScene() rather than showOverlay() for the map scene, but of course having moved newMapView outside createScene() means I have no way of removing the mapView, so it stay on-screen when the main view slides in.

There’s just no way I can seem to solve this and make a functioning app, because removing markers places the new ones in some unrelated co-ordinate system.

I would recommend updating Corona SDK to the latest public build 2100. and give that a go. If you are still having problems you will need to examine your console logs on your device and see if any errors are being generated.

Rob

Yes, docs made me think I was using the latest SDK. 2013.2100 fixed this map pin error as well, so my app is hunky dory at the moment. This thread could be deleted to not confuse a visitor who has a genuine problem with the map view. Edit: nope, I judged too quickly.

When you start Corona SDK, it should provide  you the build number on the welcome screen as well as Under the About menu item.

Rob

Yes, I was a bit too quick about it and compared that to the online docs, which say the current version is 2013.2076.

Looking at the logs I suspect some nil checks are to blame. How would I check a returned timer handle, whether it has been set or not, and how do I check a returned marker id whether a marker has been placed or not?

No, my code checks out. The marker bug is still there in 2013.2100, and it’s a bug. I just discovered that when this marker position goes off, the hitbox for the touch event is still in the correct place and triggers a callout correctly which “points” to the co-ordinates supplied it. I’ve filed the bug.

@henrik 5, do you have the bug number ? This bug is also killing us. RemovingAllMarker and adding new one is bogus and even on the latest build .2156

After looking on FogBugz we did not see any bugs relate to our problem. We have open a bug as the removeAllMarker and addMarker is currently unreliable.

Btw what is limit to add markers to map ?

I load marker data from my server on load (just json data), then create it 

local idd = myMap:addMarker( x, y, options )

After approximately 100 or 150 markers my iOS devices crushes 

I run publish starter version 2100

Oops. I was just about to start a project where I will need to put in 100+ markers. I hope there is no such limitation at all. 

@Bladko, so far we did not see any limit on the number of marker you can add. One of our thematic in our tourism app currently display 205 markers on iOS devices without any trouble.

On Android it is another story, we are working with the dev team to narrow down some unpredictable result when you addmarker after operations like removeAllMarker/SetRegion/SetCenter. 

Managed to film the crash messages and pause the frame. The lesson learned was that handlers must be at the top of the source, so that functions that use them don’t get a nil for the handler argument. In general you should define functions in load->use order.

You can store it in a variable to avoid this, and I suspect if they hadn’t been local functions it would also have worked.

It crashed with and without v1 compatbility mode and now works in both, so that rules out any problems with build 2076.

There seems to be a problem with re-adding markers with 2076, though. The first time a marker is added, it works properly. The following times a marker is added, that marker’s coordinate system vs. the map scale is out of wack - as I zoom out, the marker is moved to another part of the country or outside the view…

 

local function onbpinme(event)     myMap:setCenter(USERLAT,USERLON,true)     myMap:nearestAddress(USERLAT,USERLON,mapAddressHandler)             myMap:removeAllMarkers()     local options={title="Selected location:",subtitle="Your phone's location"}     myMap:addMarker(USERLAT,USERLON,options)     return true     end  

I will be very happy if you can locate any error in my code, or a workaround, such as “moving” a marker instead of deleting and re-adding it.

This happens with or without v1 compatibility mode. Help!!

Saving the marker ID and removing just that if it’s set, doesn’t fix it. (I’m not editing my previous post since editing posts breaks the code formatting.)

Edit: I’ve now put the map creation code at the top of the source outside any function, instead of in createScene, and I don’t self.view:insert() it anymore. I also don’t removeSelf() on exit. Still doesn’t work for the subsequent removeMarker()+addMarker().

If I don’t use removeAllMarkers() or removeMarker() at all, it works. But I’d need some way of hiding them then, or access some table that I can empty manually with some magic code.

Edit 2: Also tried using gotoScene() rather than showOverlay() for the map scene, but of course having moved newMapView outside createScene() means I have no way of removing the mapView, so it stay on-screen when the main view slides in.

There’s just no way I can seem to solve this and make a functioning app, because removing markers places the new ones in some unrelated co-ordinate system.

I would recommend updating Corona SDK to the latest public build 2100. and give that a go. If you are still having problems you will need to examine your console logs on your device and see if any errors are being generated.

Rob

Yes, docs made me think I was using the latest SDK. 2013.2100 fixed this map pin error as well, so my app is hunky dory at the moment. This thread could be deleted to not confuse a visitor who has a genuine problem with the map view. Edit: nope, I judged too quickly.

When you start Corona SDK, it should provide  you the build number on the welcome screen as well as Under the About menu item.

Rob