Android Question Google Map tracking

Hirogens

Active Member
Licensed User
Longtime User
Hello, I would like to use gmap function. My objectif is to track my own journey with gmap.
Example: If I walk in a park my app will save all the gmap point and when I finished I can see my journey.
Can you help me with the recuperation of point because I don't really know how it works ;)
Thanks =)
 

Hirogens

Active Member
Licensed User
Longtime User
java.lang.IllegalStateException: Recursive entry to executePendingTransactions
I have this error when I do this
B4X:
If show_map.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    End If
    
    show_map.Initialize("Map", panel_scrollview)
    Log("here")
    Do Until show_map.GetMap.IsInitialized
        Sleep(500)
    Loop
    If gmap.IsInitialized = True Then
        If File.ExternalWritable = False Then
            Msgbox("No rights to write"," ")
            Return
        Else
            shared = Starter.rp.GetSafeDirDefaultExternal("testgps")
            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 = Starter.listLocations
        pl.Color=Colors.Blue
        pl.ZIndex=3
    Else
        Log("Gmap not initialize")
    End If
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
To begin with - check this https://www.b4x.com/android/forum/threads/map-track.89839/#content

and then look at this: https://www.b4x.com/android/forum/threads/background-location-tracking.86395/

and then post new questions for each point that you do not understand. We are here to help.

Enjoy !!

EDIT:"
Looking at your code - You've got the permission to write, but where are you saving the latitude and the longitude every so many seconds or meters moved ?

My Suggestion:
Begin with the second link above - save your lat/longs first. Once that is done then place the markers on a map, then look at the first link and place a polyline between your points.
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
To begin with - check this https://www.b4x.com/android/forum/threads/map-track.89839/#content

and then look at this: https://www.b4x.com/android/forum/threads/background-location-tracking.86395/

and then post new questions for each point that you do not understand. We are here to help.

Enjoy !!

EDIT:"
Looking at your code - You've got the permission to write, but where are you saving the latitude and the longitude every so many seconds or meters moved ?

My Suggestion:
Begin with the second link above - save your lat/longs first. Once that is done then place the markers on a map, then look at the first link and place a polyline between your points.
I use this to save the postion:
B4X:
Sub GPS_LocationChanged (Location1 As Location)
    'Log("DANS STARTER LocationChanged")
    Dim locations As LatLng
    Dim sbb As StringBuilder
    locations.Initialize(Location1.Latitude,Location1.Longitude)
    listLocations.Add(locations)
    LatitudeReal   = Location1.Latitude
    LongitudeReal  = Location1.Longitude
    If cpt == 0 Then
        StartLocation.Initialize2(LatitudeReal, LongitudeReal)
    End If
    EndLocation.Initialize2(LatitudeReal, LongitudeReal)
    Distance = Distance + StartLocation.DistanceTo(EndLocation)
    LatitudeStart = LatitudeReal
    LongitudeEnd = LongitudeReal
    StartLocation.Initialize2(LatitudeStart, LongitudeEnd)
    sbb.Initialize
    sbb.Append("timestamp," & Chr(34) & (Round(DateTime.Now/1000)-631065600) & Chr(34) & ",s,altitude,"&Chr(34)&(Location1.Altitude)&Chr(34)&",m,distance,"&Chr(34) & Distance & Chr(34) & ",m,speed," & Chr(34) & $"$1.2{Location1.Speed}"$ & Chr(34) & ",m/s,position_lat,"& Chr(34) & (Round(Location1.Latitude*11930464.7111)) & Chr(34) & ",position_long,"&Chr(34) & (Round(Location1.Longitude*11930464.7111))&Chr(34))
    
    List1.Add(sbb.ToString)
    cpt = cpt + 1
    
    CallSub3(page_activite, "GPS_LocationChanged", Location1, Distance)
End Sub
 
Upvote 0

Hirogens

Active Member
Licensed User
Longtime User
Help us help you. Post the full error message from the logs and the exact code where it happens.
Hello, well it's strange I just uncomment my Gps part and now the issue is vanish .... But now when I try to load my journey nothing append, I just have a blank field.
This is my code:
In starter:
B4X:
Sub GPS_LocationChanged (Location1 As Location)
    'Log("DANS STARTER LocationChanged")
    Dim locations As LatLng
    Dim sbb As StringBuilder
    locations.Initialize(Location1.Latitude,Location1.Longitude)
    listLocations.Add(locations)
    LatitudeReal   = Location1.Latitude
    LongitudeReal  = Location1.Longitude
    If cpt == 0 Then
        StartLocation.Initialize2(LatitudeReal, LongitudeReal)
    End If
    EndLocation.Initialize2(LatitudeReal, LongitudeReal)
    Distance = Distance + StartLocation.DistanceTo(EndLocation)
    LatitudeStart = LatitudeReal
    LongitudeEnd = LongitudeReal
    StartLocation.Initialize2(LatitudeStart, LongitudeEnd)
    sbb.Initialize
    sbb.Append("timestamp," & Chr(34) & (Round(DateTime.Now/1000)-631065600) & Chr(34) & ",s,altitude,"&Chr(34)&(Location1.Altitude)&Chr(34)&",m,distance,"&Chr(34) & Distance & Chr(34) & ",m,speed," & Chr(34) & $"$1.2{Location1.Speed}"$ & Chr(34) & ",m/s,position_lat,"& Chr(34) & (Round(Location1.Latitude*11930464.7111)) & Chr(34) & ",position_long,"&Chr(34) & (Round(Location1.Longitude*11930464.7111))&Chr(34))
    
    List1.Add(sbb.ToString)
    cpt = cpt + 1
    
    CallSub3(page_activite, "GPS_LocationChanged", Location1, Distance)
End Sub
In Activity module:
B4X:
Public Sub GPS_LocationChanged (Location1 As Location,distance_parcourue As Double)
    Awake.KeepAlive(True)
    
    value_vitesse.Text = $"$1.1{Location1.Speed*3.6} km/h"$
    If value_vitesse.Text.SubString2(0, (value_vitesse.Text.Length - 5)) > vitesse_max Then ' Peut causer des soucis
        vitesse_max = value_vitesse.Text.SubString2(0, (value_vitesse.Text.Length - 5))
    End If

    value_distance.Text = Round2(distance_parcourue, 1)
    distance_db = value_distance.Text
    
    Awake.ReleaseKeepAlive
End Sub
B4X:
Public Sub GPS_LocationChanged (Location1 As Location,distance_parcourue As Double)
    Awake.KeepAlive(True)
    
    value_vitesse.Text = $"$1.1{Location1.Speed*3.6} km/h"$
    If value_vitesse.Text.SubString2(0, (value_vitesse.Text.Length - 5)) > vitesse_max Then ' Peut causer des soucis
        vitesse_max = value_vitesse.Text.SubString2(0, (value_vitesse.Text.Length - 5))
    End If

    value_distance.Text = Round2(distance_parcourue, 1)
    distance_db = value_distance.Text
    
    Awake.ReleaseKeepAlive
End Sub
And here the activity module call when I want to load the map:
B4X:
    Log("Status_Gps: " & Starter.gpsStarted)
    If show_map.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    End If
    
    show_map.Initialize("show_map", panel_map)
    'Log("here")
    Do Until show_map.GetMap.IsInitialized
        Sleep(400)
    Loop
    If gmap.IsInitialized Then
        If File.ExternalWritable = False Then
            Msgbox("No rights to write"," ")
            Return
        Else
            shared = Starter.rp.GetSafeDirDefaultExternal("testgps")
            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 = Starter.listLocations
        pl.Color=Colors.Blue
        pl.ZIndex=3
    Else
        Log("Gmap not initialize llll")
    End If

Sub show_map_Ready
    'Log("DANS ACT_GPS Map_ready"&Chr(0xF23C))
    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 Sub
 
Upvote 0
Top