Android Question New problem with Gmaps

Hirogens

Active Member
Licensed User
Longtime User
Hello, I thought I had fixed my issue but no :/
I had a little gmap field which working, but now I would like to put the map on full screen. When I tried to do it everything stop working :/
My old code just load my gmap, but don't recreate my journey
B4X:
Sub Globals
    Private show_map As MapFragment
    Private shared As String
    Private gmap As GoogleMap
end sub

Sub gps_design_activity
        
    show_map.Initialize("show_map", panel_map)
    
    Do Until show_map.GetMap.IsInitialized
        Sleep(300)
    Loop
    If show_map.GetMap.IsInitialized Then
        Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_ACCESS_COARSE_LOCATION)
        Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
        gmap = show_map.GetMap
        gmap.MyLocationEnabled = True
    End If
    
    
    
    If show_map.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    End If
    
    If gmap.IsInitialized Then
        If File.ExternalWritable = False Then
            Msgbox("No rights to write"," ")
            Return
        Else
            shared = Starter.rp.GetSafeDirDefaultExternal("GPS_Location")
            Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
            Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
            Wait For Activity_PermissionResult(Permission As String, Result As Boolean)
            If Result Then SaveStringExample
        End If
        '--Method
        Dim pl As Polyline = gmap.AddPolyline
        Dim lat_lng As String
        Dim lat, lng As Double
        Dim Points As List
        Points.Initialize
        CallSub(Starter, "StopGPS")
        For k = 1 To lmaps.Size - 1
            lat_lng = lmaps.Get(k)
            lat = lat_lng.SubString2(10, lat_lng.IndexOf(","))
            lng = lat_lng.SubString2(lat_lng.IndexOf(",") + 12, lat_lng.IndexOf2(",",lat_lng.IndexOf(",") +1))
            Dim ll As LatLng
            ll.Initialize(lat, lng)
            Points.add(ll)
        Next

        pl.Points = Points
        pl.Color = Colors.Blue
        pl.ZIndex=3

        Dim cp As CameraPosition = gmap.CameraPosition
        #if debug
        Log(cp)
        #end if
        Dim NewCP As CameraPosition
        
        NewCP.Initialize(lat, lng, cp.Zoom + 14)
        gmap.AnimateCamera(NewCP)
    Else
        Log("Gmap not initialize")
    End If
End Sub

Sub SaveStringExample
    Dim su As StringUtils

    If File.Exists(shared,"GPS_Pos_CSV_" & InfoActivity.activity_name & "_" & InfoActivity.activity_id & ".csv") Then
        Log("File exist")
        If Starter.gmaps.Size < 1 Then
            Dim Items() As String
            'Items.Initialize
            For Each Row() As String In su.LoadCSV (shared,"GPS_Pos_CSV_" & InfoActivity.activity_name & "_" & InfoActivity.activity_id & ".csv",",")
                For Each n As String In Row
                    Items = Regex.Split(";", N)
                    maps.Initialize
                    'maps.Put("Altitude", Items(0))
                    maps.Put("Latitude", Items(1))
                    maps.Put("Longitude", Items(2))
                    maps.Put("TimeStamp", Items(3))
                    lmaps.Add(maps)
                Next
            Next
        End If
    Else

    End If
    'Log(lmaps)
End Sub
this is my old code
 

Hirogens

Active Member
Licensed User
Longtime User
Hum looks like it's when I do this
B4X:
    Do Until show_map.GetMap.IsInitialized
        Sleep(300)
    Loop
Because when I put a break point on Do until, everything works after but whitout break point I have this error
B4X:
Map is not ready yet.
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
    at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196)
    at com.google.android.gms.maps.zzab.zza(Unknown Source:14)
    at com.google.android.gms.maps.internal.zzaq.dispatchTransaction(Unknown Source:25)
    at com.google.android.gms.internal.maps.zzb.onTransact(Unknown Source:49)
    at android.os.Binder.transact(Binder.java:604)
    at fb.b(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040400-204998136):20)
    at com.google.android.gms.maps.internal.bg.a(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040400-204998136):5)
    at com.google.maps.api.android.lib6.impl.be.run(:com.google.android.gms.dynamite_mapsdynamite@[email protected] (040400-204998136):5)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6541)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: 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
    at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:181)
    ... 14 more
 
Upvote 0
Top