Android Question Gmap issue

Hirogens

Active Member
Licensed User
Longtime User
Hello I ask again for some help with GPS map tracking.
My app log all the GPS points like this (.txt)
When I want to trace all the point I use this:
B4X:
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

        Dim pl As Polyline = gmap.AddPolyline

        pl.Points = File.ReadList(shared, "PositionsGPScycling.txt")
        pl.Color=Colors.Blue
        pl.ZIndex=3
    Else
        Log("Gmap not initialize llll")
    End If
The SaveStringExample check if the file already exist, and if it exist I try to parse this file to get the position.
I have an error with the parsing : " pl.Points = File.ReadList(shared, "PositionsGPScycling.txt")"
This is the error:
B4X:
Map is not ready yet.
** Activity (page_statistique) Resume **
Map is not ready yet.
Isinit=> true
Gmap isinit:> true
File exist
Error occurred on line: 242 (page_statistique)
java.lang.ClassCastException: java.lang.String cannot be cast to com.google.android.gms.maps.model.LatLng
    at anywheresoftware.b4a.objects.MapFragmentWrapper$PolylineWrapper.setPoints(MapFragmentWrapper.java:496)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:19)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
    at anywheresoftware.b4a.BA$2.run(BA.java:360)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6121)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

How can I resolve this issue ? And it's enough to recreate my journey ?

Thanks =)
 

Attachments

  • PositionsGPScycling.txt
    9.5 KB · Views: 262

Hirogens

Active Member
Licensed User
Longtime User
Why they’re so rounded?
Report the log of ten or more points
Well I have this and this is my code.
B4X:
Private show_map As MapFragment
Private shared As String
Private gmap As GoogleMap
Private panel_map As Panel


show_map.Initialize("show_map", panel_map)
    'Log("here")
    Do Until show_map.GetMap.IsInitialized
        Sleep(300)
    Loop
    Log("Isinit=> " & show_map.GetMap.IsInitialized)
    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
    
    
    'Log("Status_Gps: " & Starter.gpsStarted)
    If show_map.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    End If
    
    Log("Gmap isinit:> " & gmap.IsInitialized)
    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 Each k As Int = 0 In Starter.gmaps.Keys 'an array       
            lat_lng = Starter.gmaps.GetValueAt(k)
            lat = lat_lng.SubString2(0, lat_lng.IndexOf(","))
            lng = lat_lng.SubString2(lat_lng.IndexOf(",") + 1, lat_lng.Length)' - 1)
            'Log("Lat: " & lat & " Longi: " & lng)
            Dim ll As LatLng
            ll.Initialize(lat, lng)
            Log(ll)
            Points.add(ll)
        Next
        pl.Points = Points
        pl.Color= Colors.Blue
        pl.ZIndex=3
        'pl.Visibile = True
        gmap.AddMarker(lat,lng, "hello")
        Dim cp As CameraPosition
        cp.Initialize(lat, lng, gmap.CameraPosition.Zoom)
        gmap.AnimateCamera(cp)
    Else
        Log("Gmap not initialize llll")
    End If
 

Attachments

  • issue.txt
    1.3 KB · Views: 261
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Why they’re so rounded?
Report the log of ten or more points
Ok I found the problem .... Sorry to has used your time: I was working with someone who create the API Key, and he put an " " at the end of the key so nothing appeared .. I solve this with the tuto when Erel explain the blank map issue :/
Sorry again
 
Upvote 0
Top