Android Question [B4xPages] [SOLVED] GoogleMaps outside MainPage not working: AddPageAndCreate vs AddPage

Mashiane

Expert
Licensed User
Longtime User
Ola

I need some advise. I have used the google maps example and however have a Google Map on another page outside the MainPage.

With

B4X:
B4XPages.AddPageAndCreate("mapPage", mapPage)

The app does not work, however with

B4X:
B4XPages.AddPage("mapPage", mapPage)

Everything is fine.

For my context we prefer the former method as it brings a little bit of speed to the process, i.e. when you show the page, all elements are created.

I have attached the project.

Thanks a mill!
 

Attachments

  • B4XGoogleMaps.zip
    16.9 KB · Views: 258
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
You should use the link from B4XMainPage to export the project:

1611139044572.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I see the problem. The map parent needs to be in the layout tree when the map is loaded.

This code seems to work properly:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    B4XPages.GetNativeParent(Me).AddView(Root, 0, 0, 100%x, 100%y) '<----------
    Root.Visible = False
    Root.LoadLayout("MainPage")
    MP = B4XPages.MainPage
    btnJumpToParis.Enabled = False
    If gmap.IsInitialized = False Then
        Wait For (InitializeMap) Complete (Success As Boolean)
        MapReady = Success
        If MapReady Then
            Log("map ready")
            btnJumpToParis.Enabled = True
            gmap.AddMarker(0, 0, "Center")
        End If
    End If
End Sub

Private Sub B4XPage_Appear
    Root.Visible = True
End Sub
 
Upvote 0
Top