Android Question B4XMap - draw a line

AlpVir

Well-Known Member
Licensed User
Longtime User
I'm trying to draw a GPS track on a map created using the B4XMap library.
Documentation is poor and the only useful instruction I've found is the following (draw a line between 2 dots)
B4X:
shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(48.856614,2.3522219),coMapUtilities.initLatLng(31.630000,-8.008889),fxui.Color_ARGB(128,255,0,255),1dip,"Paris to Marrakech")))

However I can not indicate latitude and longitude with variables :
Point 1: (Lt, Lg)
Point 2: (PrecLt, PrecLg)

Something like that :
B4X:
shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(" & PrecLt & "," & PrecLg & "),coMapUtilities.initLatLng(" & Lg & "," & Lt & "),fxui.Color_ARGB(128,255,0,255),1dip,"test")))
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Here is the project, expanded with all classes.
I marked with 4 apostrophes
''''
the points where I intervened.
Had to sort some minor things out such as missing image files and not looked at it properly yet, but I think the problem is you are not doing something like this in Main:

B4X:
Sub SetupMapdgOSM(tLLPatient As TMapLatLng, _
                  tLLCenter As TMapLatLng, _
                  BB As TMapBoxLatLng, _
                  iMapZoom As Int, _
                  iID As Int, _
                  bDrawCenterLines As Boolean)
    
    Dim tLLCurrentLocation As TMapLatLng

    'Lat and Lon of current patient or mapcenter
    '-------------------------------------------
    If tLLPatient = Null Then
        If tLLCenter = Null Then
            tLLCenter = MapUtilities.initLatLng(LocationLG.Latitude, LocationLG.Longitude)
        End If
        cMP.MapCenter = tLLCenter
    Else
        cMP.MapCenter = tLLPatient
    End If
    
    If tLLCenter = Null Then
        tLLCenter = cMP.MapCenter
    End If
    
    If cMP.MapCenter = Null Then
        tLLCurrentLocation = MapUtilities.initLatLng(Tracker.dCurrentLatitude, Tracker.dCurrentLongitude)
    Else
        tLLCurrentLocation = cMP.MapCenter
    End If
    
    If cMP.iEMIS_NUMBER <> -1 Then
        If iID = cMP.iEMIS_NUMBER Then
            SetCurrentPatientMarker(tLLCenter, False)
        End If
    Else
        'this happens after clearing the find patient dialog
        'change any current patient marker (filled circle) to a non-current patient marker (not filled)
        '----------------------------------------------------------------------------------------------
        For Each iKey As Int In mapMarkerCircles.Keys
            Dim cMSC As clsMapShapeCircle = mapMarkerCircles.Get(iKey)
            Dim tMSC As TMapShapeCircle = cMSC.get_Shape
            If tMSC.fFilled Then
                tMSC.fFilled = False
                cMSC.set_Shape(tMSC)
                Dim cMSC2 As clsMapShapeCircle = mapShapes.Get(iKey)
                Dim tMSC2 As TMapShapeCircle = cMSC2.get_Shape
                tMSC2.fFilled = False
                cMSC2.set_Shape(tMSC2)
                Exit
            End If
        Next
    End If
    
    If BB = Null Then
        If iMapZoom <> -1 Then
            iZoom = iMapZoom
        End If
    Else
        iZoom = MapUtilities.GetZoomToShowAll(tLLCenter, BB)
    End If
    
    fMap = MapUtilities.initMap( _
            tLLCenter, _                                  'alatLng (eg lat/lon of Current patient)
            iZoom, _                                     'aZoomLevel
            0, _                                        'aCompassDirection
            True, _                                        'aOffLineMode
            False, _                                    'aShowMenu
            cMP.bShowGrid, _                            'aShowGrid
            True, _                                        'aShowCentre
            False, _                                    'aShowLandMark
            False, _                                    'aShowCentreLatLng
            False, _                                    'aShowZoom
            False, _                                    'aShowScale
            False, _                                    'aShowCompass
            True, _                                        'aShowShapes
            mapShapes, _                                'aShapes (map)
            False, _                                    'aShowGPS
            False, _                                    'aFollowGPS
            MapUtilities.initGPS(tLLCurrentLocation, 0), _ 'aGPS
            False)                                       'bMultiShapeClick
            

    Sleep(10) '>>>>  this is needed to  avoid crash: fViewTiles in cvMap not initialized yet
    cvMap1.CenterLatLng = tLLCenter
    Sleep(10) '>>>>  this is needed to  avoid crash: fViewTiles in cvMap not initialized yet
    cvMap1.Map = fMap
    cvMap1.Draw
    
    If bDrawCenterLines Then
        Sleep(0)
        cvMap1.DrawCenterLines(Colors.Red, 1, cMP.bFullMapCenterLines, False)
        Sleep(0)
    End If
    
    If iID > -1 Then
        lblPatMap.Text = "  " & cMP.GetPatLabelString(-1)
    End If
    
End Sub

Have a look at that first.

RBS
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
I'm sorry but by inserting the SetupMapdgOSM sub the number of errors, unresolved references and possible unanswered questions increases.
Without a definitive solution I think I'll have to abandon this library which seemed to me very powerful and suitable for my purposes.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I'm sorry but by inserting the SetupMapdgOSM sub the number of errors, unresolved references and possible unanswered questions increases.
Without a definitive solution I think I'll have to abandon this library which seemed to me very powerful and suitable for my purposes.
You can't just insert that Sub as it is very particular to my app.
The important thing is:

fMap = MapUtilities.initMap

As, unless I overlooked it, I didn't see that in your posted project.
Will have a look later and see if I can fix it.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
You can't just insert that Sub as it is very particular to my app.
The important thing is:

fMap = MapUtilities.initMap

As, unless I overlooked it, I didn't see that in your posted project.
Will have a look later and see if I can fix it.

RBS
The other thing is that it would be better to post a project that just shows the map you are dealing with and with a button that will do all the internet stuff.
At least we can then see that the map is showing OK and then concentrate on the troublesome other things.

RBS
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
As I assumed the original code was right but some instructions were put in the wrong places.
The map is now displayed correctly. And I used the library.
I just deleted the fcvmap_ready sub and changed the following code
B4X:
        If JobDownload.Success Then
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                File.Delete(GlobalCartellaThisApp, TracciaWeb)
            End If
            Dim out As OutputStream = File.OpenOutput(GlobalCartellaThisApp,  TracciaWeb, False)
            File.Copy2(JobDownload.GetInputStream, out)
            out.Close
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                LoadShapes  (TracciaWeb)
                If shapes.Size>1 Then
                    fcvMap.TileServer="https://a.tile.openstreetmap.org/"   ' default
                    fcvMap.UserAgent="User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0"
                    fMap=coMapUtilities.initMap(coMapUtilities.initLatLng(FineLt, FineLg),18,0,False,True,True,True,False,True,True, True, False,True, _
                                    shapes, _
                                    True,False,coMapUtilities.initGPS(coMapUtilities.initLatLng(0,0),0))
                    fcvMap.Map=fMap
                    fcvMap.draw
                Else
                    Log("No number one")
                End If
            End If
        End If
        JobDownload.Release
One last question: I used the default tile server https://a.tile.openstreetmap.org/
What other tile servers are available ?
Thanks again.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
As I assumed the original code was right but some instructions were put in the wrong places.
The map is now displayed correctly. And I used the library.
I just deleted the fcvmap_ready sub and changed the following code
B4X:
        If JobDownload.Success Then
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                File.Delete(GlobalCartellaThisApp, TracciaWeb)
            End If
            Dim out As OutputStream = File.OpenOutput(GlobalCartellaThisApp,  TracciaWeb, False)
            File.Copy2(JobDownload.GetInputStream, out)
            out.Close
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                LoadShapes  (TracciaWeb)
                If shapes.Size>1 Then
                    fcvMap.TileServer="https://a.tile.openstreetmap.org/"   ' default
                    fcvMap.UserAgent="User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0"
                    fMap=coMapUtilities.initMap(coMapUtilities.initLatLng(FineLt, FineLg),18,0,False,True,True,True,False,True,True, True, False,True, _
                                    shapes, _
                                    True,False,coMapUtilities.initGPS(coMapUtilities.initLatLng(0,0),0))
                    fcvMap.Map=fMap
                    fcvMap.draw
                Else
                    Log("No number one")
                End If
            End If
        End If
        JobDownload.Release
One last question: I used the default tile server https://a.tile.openstreetmap.org/
What other tile servers are available ?
Thanks again.
Are you saying it is all working OK now?
In that case: good news!

Not sure what other servers are available, never had a problem with the one that you and I use.
I changed the header as I had trouble with the previous one, see code:

B4X:
    Try
        j.Initialize("", Me)
        j.Download("https://a.tile.openstreetmap.org/" & strTiles)
        
        'with this one downloading of tiles failed
        '-----------------------------------------
        'j.GetRequest.SetHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0")
        j.GetRequest.SetHeader("User-Agent", "Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10")

RBS
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Do you want to draw a polyline of this data?
1676480276393.png

Note:
The URL is no longer active.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
The URL is now reactivated.
Yes, using the B4XMap library I display a GPS track (see attached screenshot) with the instruction
B4X:
shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng( PrecLT,PrecLg),coMapUtilities.initLatLng(Lt, Lg),Colors.ARGB(128,255,0,255),3dip,"")))
The idea would be to give the user the possibility to choose between different tile-servers. Now I use the default one with instructions
B4X:
fcvMap.TileServer="https://a.tile.openstreetmap.org/"
fcvMap.UserAgent="User-Agent/Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/ 531.21.102011-10-16 20:23:10"
and it doesn't seem to me that the B4XMap library provides the possibility of using the getTileFromInternet sub.
 

Attachments

  • MapToday.jpg
    MapToday.jpg
    198.7 KB · Views: 136
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
The URL is now reactivated.
Yes, using the B4XMap library I display a GPS track (see attached screenshot) with the instruction
B4X:
shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng( PrecLT,PrecLg),coMapUtilities.initLatLng(Lt, Lg),Colors.ARGB(128,255,0,255),3dip,"")))
The idea would be to give the user the possibility to choose between different tile-servers. Now I use the default one with instructions
B4X:
fcvMap.TileServer="https://a.tile.openstreetmap.org/"
fcvMap.UserAgent="User-Agent/Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/ 531.21.102011-10-16 20:23:10"
and it doesn't seem to me that the B4XMap library provides the possibility of using the getTileFromInternet sub.
> and it doesn't seem to me that the B4XMap library provides the possibility of using the getTileFromInternet sub.

Works OK here.
What error/problem are you seeing?

RBS
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
There are currently no errors in my app and the GPS track is displayed correctly. @ RB Smissaert : Thanks for your help.
My previous post was addressed to @TILogistic who pointed out the possibility of using another tile-server.
However I don't know how to insert the Google tile-server inside the B4XMap library.
I specify that I would like to continue using this library and not the class modules.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
There are currently no errors in my app and the GPS track is displayed correctly. @ RB Smissaert : Thanks for your help.
My previous post was addressed to @TILogistic who pointed out the possibility of using another tile-server.
However I don't know how to insert the Google tile-server inside the B4XMap library.
I specify that I would like to continue using this library and not the class modules.
Nice to hear it is all working OK.
Not sure what you mean with Google tile-server.
I thought that the B4XMap library/classes only worked with OSM.
I very much prefer to use the classes for various reasons, but it is easy to make a library from the classes and also
vice-versa to get the classes from the library. Just unzip the library.

RBS
 
Upvote 0

hasanaydin52

Member
Licensed User
Longtime User
As I assumed the original code was right but some instructions were put in the wrong places.
The map is now displayed correctly. And I used the library.
I just deleted the fcvmap_ready sub and changed the following code
B4X:
        If JobDownload.Success Then
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                File.Delete(GlobalCartellaThisApp, TracciaWeb)
            End If
            Dim out As OutputStream = File.OpenOutput(GlobalCartellaThisApp,  TracciaWeb, False)
            File.Copy2(JobDownload.GetInputStream, out)
            out.Close
            If File.Exists(GlobalCartellaThisApp, TracciaWeb) = True Then
                LoadShapes  (TracciaWeb)
                If shapes.Size>1 Then
                    fcvMap.TileServer="https://a.tile.openstreetmap.org/"   ' default
                    fcvMap.UserAgent="User-AgentMozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0"
                    fMap=coMapUtilities.initMap(coMapUtilities.initLatLng(FineLt, FineLg),18,0,False,True,True,True,False,True,True, True, False,True, _
                                    shapes, _
                                    True,False,coMapUtilities.initGPS(coMapUtilities.initLatLng(0,0),0))
                    fcvMap.Map=fMap
                    fcvMap.draw
                Else
                    Log("No number one")
                End If
            End If
        End If
        JobDownload.Release
One last question: I used the default tile server https://a.tile.openstreetmap.org/
What other tile servers are available ?
Thanks again.
i cant see TileServer in cvMap class.
 
Upvote 0

papajds

Member
Hi,

I try to draw a line on the map, but nothing is displayed, and no error...
I copied, to test a line which works when launching the program, but in a button, it does not work.
I think something is missing...but I can't find it

can anyone help me?

Thanks.

add line:
Public Sub  Button9_Click
    Dim shapes As List
    shapes.Initialize
            shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(51.5073509,-0.1277583),coMapUtilities.initLatLng(48.856614,2.3522219),fxui.Color_Blue,4dip,"London to Paris")))
        fcvMap.draw
    
End Sub
 
Upvote 0

papajds

Member
Hi,
i found my mistake:

2 lines removed and it's ok


ok:
Public Sub  Button9_Click
            shapes.Add(coMapUtilities.instanceShapeLine(fcvMap,coMapUtilities.initShapeLine(coMapUtilities.initLatLng(51.5073509,-0.1277583),coMapUtilities.initLatLng(48.856614,2.3522219),fxui.Color_Blue,4dip,"London to Paris")))
        fcvMap.draw
    
End Sub
 
Upvote 0
Top