Android Question How to create a gmap polyline to smooth the line and how to implement StartForeground ?

Sapta

Member
Licensed User
Longtime User
Hi all,
I created a program to track when running. The obstacles I found,

1. How to write in the gmap so that it is smooth? because this time the result is like this (the lines are stiff, especially at the turn). I use this code, is there anything missing ?

B4X:
pl = GMap.AddPolyline
l1.Initialize(LatitudeStart, LongitudeStart)
l2.Initialize(LatitudeReal, LongitudeReal)
Points.Initialize
Points.Add(l1)
Points.Add(l2)
If SettingWhiteMap = True Then
    pl.Color=Colors.White
Else
    pl.Color=Colors.Blue
End If
pl.points = Points

8RfYu0G.png



It wants to be like this

T8VmGhV.png


Thank you
 
Last edited:

BillMeyer

Well-Known Member
Licensed User
Longtime User
Question 1:

With Google Maps "Snap To Road" API you can "smooth" your track provided you stay on a road. You can read more here

You require a Key from Google.

Here is some code, lifted from B4J - but should serve as a guide to doing it in B4A.

B4X:
             Dim StR As String
             Dim LatLng(16) As String

'            StR = "path="&LatLng(1)&","&LatLng(8)&"|"&LatLng(2)&","&LatLng(9)&"&interpolate=True&key=AIzaSyC324Thq0DI1l_xPmyQP7LYU3n1rkEOkxI"
            StR = "path="&LatLng(1)&","&LatLng(8)&"|"&LatLng(2)&","&LatLng(9)&"|"&LatLng(3)&","&LatLng(10)&"|"&LatLng(4)&","&LatLng(11)&"|"&LatLng(5)&","&LatLng(12)&"|"&LatLng(6)&","&LatLng(13)&"|"&LatLng(7)&","&LatLng(14)&"&interpolate=True&key=Your Key Here"

            Log("Post String: "&CRLF&StR)

            Dim j1 As HttpJob
            j1.Initialize("", Me)

            j1.PostString("https://roads.googleapis.com/v1/snapToRoads",StR)
            Wait For (j1) JobDone(j2 As HttpJob)
             If j2.Success Then
                 Log(j2.GetString)
            End If

The other questions, as @Erel says, separate threads helps to keep them from getting lost in other threads and someone who has done this previously will spot it and answer for you.

Enjoy your day
 
Upvote 0

Sapta

Member
Licensed User
Longtime User
Please create a new thread for each question.

Ok @Erel , I've revised this question into sections. Thank you



Question 1:

With Google Maps "Snap To Road" API you can "smooth" your track provided you stay on a road. You can read more here

You require a Key from Google.

Here is some code, lifted from B4J - but should serve as a guide to doing it in B4A.

B4X:
             Dim StR As String
             Dim LatLng(16) As String

'            StR = "path="&LatLng(1)&","&LatLng(8)&"|"&LatLng(2)&","&LatLng(9)&"&interpolate=True&key=AIzaSyC324Thq0DI1l_xPmyQP7LYU3n1rkEOkxI"
            StR = "path="&LatLng(1)&","&LatLng(8)&"|"&LatLng(2)&","&LatLng(9)&"|"&LatLng(3)&","&LatLng(10)&"|"&LatLng(4)&","&LatLng(11)&"|"&LatLng(5)&","&LatLng(12)&"|"&LatLng(6)&","&LatLng(13)&"|"&LatLng(7)&","&LatLng(14)&"&interpolate=True&key=Your Key Here"

            Log("Post String: "&CRLF&StR)

            Dim j1 As HttpJob
            j1.Initialize("", Me)

            j1.PostString("https://roads.googleapis.com/v1/snapToRoads",StR)
            Wait For (j1) JobDone(j2 As HttpJob)
             If j2.Success Then
                 Log(j2.GetString)
            End If

The other questions, as @Erel says, separate threads helps to keep them from getting lost in other threads and someone who has done this previously will spot it and answer for you.

Enjoy your day

Hi @BillMeyer
What if it is not on the road? because it could run in the fields, parks or other places. I've updated the sample image like the example I want.

But I am grateful for your answer because it has increased my knowledge. Thank you. :)
 
Upvote 0

BillMeyer

Well-Known Member
Licensed User
Longtime User
@Sapta,

Sorry, my knowledge ends at the edge of the road.
 
Upvote 0
Top