0
votes

I need some help with the MapView in Corona SDK. I want to put the map as background (but with all functions) and, in this case, a button to the front. Here is my code:

function scene:createScene( event )
    local group = self.view

    if ( system.getInfo( "environment" ) == "simulator" ) then
        local simulatorMessage = "Maps not supported in Corona Simulator.\nYou must build for iOS or Android to test native.newMapView() support."
        local label = display.newText( simulatorMessage, 36, 40, 270, 0, native.systemFont, 12 )
        label.anchorX = 0
        label.anchorY = 0
    end

    myMap = native.newMapView( 20, 20, display.contentWidth, display.contentHeight )

    if ( myMap ) then
        myMap.mapType = "normal"
        myMap.x = display.contentCenterX
        myMap.y = display.contentCenterY
        myMap:setCenter( currentLatitude, currentLongitude )
        myMap:addEventListener("mapLocation", mapLocationListener)
    end    

    backBtn = widget.newButton
    {
        id="backButton",
        label="Back",
        fontSize="30",
        labelColor={ default={1, 1, 1}, over={0, 0, 0, 0.5} },
        defaultFile="images/button.png",
        width = dispWidth * 0.25, height = dispHeight * 0.1,
        onRelease = onBackBtnRelease
    }
    backBtn.anchorX = 0.5
    backBtn.anchorY = 0.5
    backBtn.x = display.contentWidth * 0.8
    backBtn.y = dispHeight * 0.8
    backBtn:toFront()

    group:insert( backBtn )
    group:toFront() --second try to put that button to front
end

Since the MapView is a native object I can't add it to any group and 'mapView:toBack()' doesn't work as well ('attempt to index upvalue 'myMap' (a nil value)'). In Corona SDK the button appears without the map, as expected. On device I get the map without my button, not as expected.

Is it any possible to put a native object to the back, or to force something to be in the front?

2

2 Answers

1
votes

What you are trying to do with the map and the button is not currently possible with CoronaSDK.

Indeed the MapView is a native object. According to Corona's documentation, you cannot place other objects on top of a MapView.

The documentation says:

Map objects, like other native display objects, cannot be inserted into groups and are always displayed on top of regular Display Objects (groups, vector, images, and text).

See documentation here

Good luck coding.

0
votes

First Check the Following :

If button doesn't appear on device most common problem will be , you might misspell the Image names(Check for Caps) or check the path of the file is proper or not.

To know in detail about the mapView : http://docs.coronalabs.com/api/library/native/newMapView.html

I know you might have visited already, its better you look again.

Thanks,