How to use a MapView on a TabBar Widget View?

What is the best way to use a Google map view on a single view of a Tabbar widget? I can get the map view to show, but how do I remove or hide it when moving to the other tabs?

Thanks,
Chris [import]uid: 79415 topic_id: 21066 reply_id: 321066[/import]

@chris,

Insert you map into a group:

[lua]yourGroup:insert(yourMap)[/lua]

Then later on your .lua file just remove the group (when switching between tab-views) as below:

[lua]yourGroup:removeSelf()[/lua]

PS: Am not saying it the best way to do it, BUT it does work btw.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 21066 reply_id: 83237[/import]

@Rodrigo
Wish that is true. MapViews are native objects which cannot be inserted into a group. :frowning: [import]uid: 19297 topic_id: 21066 reply_id: 85231[/import]

@ckausik ,

Honestly my apologies.

HOWEVER, I`ve done it mate, please, did you TRY that before repeat (what all of us “know”), that being native it cannot be inserted into a group?

Please, have a try.

PS: Im posting below a snippet code of mine that Ive been using and released on iOS.

[lua]-- Create a native MapView (requires XCode Simulator build or device build)
– You can create multiple maps, if you like…
myMap = native.newMapView( 7, 23, 310, 210)
myMap.mapType = “normal” – other mapType options are “satellite” or “hybrid”

– The MapView is just another Corona display object, and can be moved or rotated, etc.
myMap.x = display.contentWidth / 2
myMap.y = 130

– Initialize map to a real location, since default location (0,0) is not very interesting
myMap:setCenter( 37.331692, -122.030456 )
g:insert(myMap)[/lua]
PS2: Ive been using this code above combined together the TabView example that Coronas Sample Code have. (from 706 corona builds) [import]uid: 89165 topic_id: 21066 reply_id: 85378[/import]

@RSCdev,
I wound up using this same technique in my code. Thanks for validating this is how you are doing it.

The key for me was being able to hide the Mapview when switching to other tabs.

  • Called when scene is about to move offscreen:
    function scene:exitScene( event )
    local group = self.view
    myMap.isVisible = false

– Remove listener for the address lookup result
Runtime:removeEventListener( “mapAddress”, mapAddressHandler )
– 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
–myMap.remove
Runtime:removeEventListener( “mapAddress”, mapAddressHandler )

– INSERT code here (e.g. remove listeners, remove widgets, save state variables, etc.)

end

Thanks,
Chris [import]uid: 79415 topic_id: 21066 reply_id: 86351[/import]

@Chris, Glad to help you out man!
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 21066 reply_id: 86381[/import]

Guys, I’m new to Corona i’ve this :
function scene2:createScene( event )
local groupMap = self.view
myMap = native.newMapView( 0, 20, 320, 400 )

myMap.isZoomEnabled = true
myMap.isScrollEnabled = true
myMap:setCenter( 29.345072, 47.679634, isAnimated )
groupMap:insert(myMap)
end
scene2:addEventListener( “createScene”, scene2 )

i can remove the map when click on tab buttons to other scene but when i get back to the Map scene it never show again. how can i do this ? please help [import]uid: 129462 topic_id: 21066 reply_id: 103213[/import]

@ramy,

am not storyboard`s API expert at all, but what would happen if instead you have your Map being created in the createScene() you have it into the enterScene() function?

Would that still not show you the Map again?
PS: I think that if you do not purge()/remove() your scene the Map would show up into the enterScene() function. Sorry but am also not sure at all, it`s just “speculation” trying to help you out.

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 21066 reply_id: 103215[/import]

@ Rodrigo

Man you saved my life :slight_smile: your idea of putting it into enterscene was great :slight_smile: thank you very much it worked. [import]uid: 129462 topic_id: 21066 reply_id: 103241[/import]

@ramy,

WOW, glad to hear that mate! :wink:

Cheers,
Rodrigo. [import]uid: 89165 topic_id: 21066 reply_id: 103243[/import]

@Rodrigo :slight_smile:

Cheers Mate :slight_smile: [import]uid: 129462 topic_id: 21066 reply_id: 103255[/import]