Spanish Problemas con la Inicialización de Google Maps en B4A

Emerito

Active Member
Licensed User
Longtime User
Hola a todos,

Estoy teniendo problemas al inicializar Google Maps en mi aplicación B4A. El siguiente código intenta obtener el mapa, pero no se inicializa correctamente a menos que use un punto de interrupción.

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

End Sub

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region


Sub Globals
Dim mFragment As MapFragment
Dim gmap As GoogleMap
Dim MapPanel As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("prueba4") ' Cargar el diseño que contiene el MapFragment

MapPanel.Initialize("")
Activity.AddView(MapPanel, 0, 0, 100%x, 100%y)
If mFragment.IsGooglePlayServicesAvailable = False Then
ToastMessageShow("Google Play services not available.", True)
Else
mFragment.Initialize("Map", MapPanel)
End If
End Sub

Sub Map_Ready
Log("map ready")
gmap = mFragment.GetMap
If gmap.IsInitialized = False Then
ToastMessageShow("Error initializing map.", True)
Else
'gmap.AddMarker(36, 15, "Hello!!!")

gmap.AddMarker3(36,15, "yo", LoadBitmap(File.DirAssets, "ic_person128.png"))



Dim cp As CameraPosition
cp.Initialize(36, 15, gmap.CameraPosition.Zoom)
gmap.AnimateCamera(cp)
End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub





He probado varios enfoques, incluyendo el uso de un Timer y un Handler, pero el problema persiste. Estoy utilizando [especifica la versión de B4A y el dispositivo].

Cualquier ayuda sería apreciada.
 

josejad

Expert
Licensed User
Longtime User
Hi emerito. This is the english part of the forum, you must post in english here, or post in the spanish forum

Hola emerito, hay que escribir en inglés en el foro, a menos que lo haga en la sección en español.

Usa también los tags [code] … tu código … [/code]
 
Reactions: zed
Upvote 0

Emerito

Active Member
Licensed User
Longtime User
Please forgive me, I understand the importance of forms. I went to the wrong forum. I did not mean to be annoying. I will try to prevent this from happening again. I am writing this in Spanish and will now use the translator.
I hope you understand. I was trying to find the forum in Spanish, but I can't seem to find it. It's been a long time since I used B4A, and now I'm trying again.
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Anyway, is a good idea to publish in this part of the forum translating your message (remember, using code tags). You will get more answers here than in the Spanish forum

No es mala idea dejar tu pregunta aquí en inglés, (usa los tags code para que sea más legible el código). Vas a recibir más respuestas que en el foro en español. También recibes más ayuda si subes un proyecto que muestre tu problema.
 
Upvote 0

Emerito

Active Member
Licensed User
Longtime User
B4X:
#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region


Sub Globals
   Dim mFragment As MapFragment
   Dim gmap As GoogleMap
   Dim MapPanel As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("prueba4") ' Cargar el diseño que contiene el MapFragment

    MapPanel.Initialize("")
    Activity.AddView(MapPanel, 0, 0, 100%x, 100%y)
    If mFragment.IsGooglePlayServicesAvailable = False Then
      ToastMessageShow("Google Play services not available.", True)
   Else
      mFragment.Initialize("Map", MapPanel)
   End If
End Sub

Sub Map_Ready
   Log("map ready")
   gmap = mFragment.GetMap
   If gmap.IsInitialized = False Then
      ToastMessageShow("Error initializing map.", True)
   Else
      'gmap.AddMarker(36, 15, "Hello!!!")
        gmap.AddMarker3(36,15, "yo", LoadBitmap(File.DirAssets, "ic_person128.png"))
      Dim cp As CameraPosition
      cp.Initialize(36, 15, gmap.CameraPosition.Zoom)
      gmap.AnimateCamera(cp)
   End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

This code only works correctly if I include a breakpoint on the line; If mFragment ...
When I try to run it directly with F5 it doesn't work. It gives the following error: Map is not ready yet. java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object anywheresoftware.b4a.objects.collections.Map.Get(java.lang.Object)' on a null object reference.
I don't know how to solve it
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This code only works correctly if I include a breakpoint on the line; If mFragment ...
The correct way to add a GoogleMap is to place the Map into a layout and load that layoutfile.

See the GoogleMaps Example for the correct code to see.
 
Upvote 0

Emerito

Active Member
Licensed User
Longtime User
I have already done it by adding a MapFragment from the designer and the same thing happens. Where can I find the example?
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Where can I find the example?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…