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: 249

Hirogens

Active Member
Licensed User
Longtime User
File.ReadList returns a list with string elements. You need to create a new list where each item in that list is a LatLng object.
When you say list is a LatLng Object, I give this List to a Polyline object and just do this
B4X:
pl.Points = File.ReadList(shared, "PositionsGPScycling.txt")
        pl.Color=Colors.Blue
        pl.ZIndex=3
Or I need to use something different ?

Thanks !
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
This cannot work. File.ReadList returns a List with string elements.
You need to create a new list with LatLng elements.
So if I log all my Long/lat in a file every seconde. When I finish my journey I parse this file and recup' all my value in the Object, it can works ?
Sorry I don't realy know how work this Object :/
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
Something like this:

B4X:
Dim Points as list

forEach ....
Dim ll As LatLng
ll.Initialize(lat, lon)
Points.Add(ll)
Next

pl.Points = Points

You need to scan your file, for each row retrieve the lat/lon values (float), create the ll objects and put it in Points list.
 
Last edited:
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Something like this:

B4X:
Dim Points as list

forEach ....
Dim ll As LatLng
ll.Initialize(lat, lon)
Points.Add(ll)
Next

pl.Points = Points

You need to scan your file, for each row retrieve the lat/lon values (float), create the ll objects and put it in Points list.
Hello, I do this
B4X:
Dim pl As Polyline = gmap.AddPolyline
        
        For Each k As Int In Starter.gmaps 'an array
            Dim ll As LatLng
            Dim lat_lng As String
            Dim lat As Double
            Dim lng As Double
            lat_lng = Starter.gmaps.GetValueAt(k)
            lat = lat_lng.SubString2(0, lat_lng.IndexOf(","))
            lng = lat_lng.SubString2(lat_lng.IndexOf(","), lat_lng.Length)
            ll.Initialize(lat, lng)       
        Next
        pl.Points = ll
        pl.Color=Colors.Blue
        pl.ZIndex=3
my gmaps value is a Map which contain a string with that : "Lattitude,longitude"
 
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
you're missing a list.

B4X:
Dim pl As Polyline = gmap.AddPolyline
Dim lat_lng As String
Dim lat, lng As Double
Dim Points as list
For Each k As Int In Starter.gmaps 'an array
  lat_lng = Starter.gmaps.GetValueAt(k)
  lat = lat_lng.SubString2(0, lat_lng.IndexOf(","))
  lng = lat_lng.SubString2(lat_lng.IndexOf(","), lat_lng.Length)
  Dim ll As LatLng
  ll.Initialize(lat, lng)      
  Points.add (ll)
Next
pl.Points = Points
pl.Color=Colors.Blue
pl.ZIndex=3
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
you're missing a list.

B4X:
Dim pl As Polyline = gmap.AddPolyline
Dim lat_lng As String
Dim lat, lng As Double
Dim Points as list
For Each k As Int In Starter.gmaps 'an array
  lat_lng = Starter.gmaps.GetValueAt(k)
  lat = lat_lng.SubString2(0, lat_lng.IndexOf(","))
  lng = lat_lng.SubString2(lat_lng.IndexOf(","), lat_lng.Length)
  Dim ll As LatLng
  ll.Initialize(lat, lng)    
  Points.add (ll)
Next
pl.Points = Points
pl.Color=Colors.Blue
pl.ZIndex=3
Well I do want you said but I have this
B4X:
Error occurred on line: 251 (page_statistique)
java.lang.RuntimeException: Object should first be initialized (List).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.collections.List.Add(List.java:76)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:755)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:345)
    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)

Edit: My bad forgot to initialize Points;)
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Try to log your latlng points, maybe you’re not extracting them correctly
So when I finish my activity I use File.WriteMap to create a .txt file with the values (pb: I would like to stock in Key order like 0,1,2,3,etc but actually it's stock randomly :/)
My lat/long are like this
 

Attachments

  • issue.txt
    1.9 KB · Views: 253
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
That is.
I don’t know where do you live but it’s evident in the file that the coordinates are not correct.
Double check it, especially just before creating the latlng object.
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
That is.
I don’t know where do you live but it’s evident in the file that the coordinates are not correct.
Double check it, especially just before creating the latlng object.
I live in France, but when I get the postion I do this
B4X:
If gmaps.IsInitialized Then
        gmaps.Put(Key, Round(Location1.Latitude*11930464.7111) & "," & Round(Location1.Longitude*11930464.7111))
        Key = Key + 1
        Log("+1")
    End If

Edit: Now I have that but no map design: Lat: 49 Longi: 6
 
Last edited:
Upvote 0

marcick

Well-Known Member
Licensed User
Longtime User
????
I don’t understand what that calculation is for.
Just store latitude and longitude as they’re.
You can use Format to store them as string with fixed number of digit eventually
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
????
I don’t understand what that calculation is for.
Just store latitude and longitude as they’re.
You can use Format to store them as string with fixed number of digit eventually
Now I have something better but still no map :/
(Lat 49 long:6) Values rounds
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
No Point on the map :/ I check if everything are initialize, I put a break point on pl.Points = Points I pass here but nothing appear on my map :/
 
Upvote 0
Top