Android Question OSMDROID, MapView and traces GPX

AlpVir

Well-Known Member
Licensed User
Longtime User
Use the library OSMDROID and MapView.
With this simple code I see the traces of PLT type (Oziexplorer).
B4X:
    TextReader1.Initialize(File.OpenInput(File.DirRootExternal,  NomeTraccia))
        '--- 6 linee inutili
        For i=1 To 6
            Riga = TextReader1.ReadLine
        Next        
        Do While Riga <> Null
            Riga = TextReader1.ReadLine
            If IsNullString(Riga) = False  Then
                ele = Regex.Split(",",Riga)
                Lt=ele(0) : Lg= ele(1) : H= ele(3) * 0.3048
                PathOverlay1.AddPoint  (Lt,Lg)
            End If
        Loop
        TextReader1.Close
It would be possible to see traces of the type GPX (and TRK) ?
As ?
Thanks in advance.
 

Mark Read

Well-Known Member
Licensed User
Longtime User
This any help to you?

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    Type GPXFileToParse (gPath As String, gFile As String, gMarkerIcon As BitmapDrawable)
    Dim lati As String
    Dim loni As String
    Dim desc As String
    Dim parser As SaxParser
    Dim gList As List
End Sub

'Initialise the parser and the icon for the POI
Sub Initialise(gPath As String, gFile As String, gMarkerIcon As BitmapDrawable) As GPXFileToParse
    Dim MyGpx As GPXFileToParse
    MyGpx.gPath=gPath
    MyGpx.gFile=gFile
    MyGpx.gMarkerIcon=gMarkerIcon
   
   
    gList.Initialize
    parser.Initialize    'initialise the parser
    Return MyGpx
End Sub

'Select a waypoint gpx file and parse it.
Sub wpParse (GPX As GPXFileToParse) As List
    Dim In As InputStream
    In = File.OpenInput(GPX.gPath,GPX.gFile)
    parser.Parse(In, "Parser")
    In.Close
    Return gList
End Sub

'    Required for parser
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
    If Name="wpt" Or Name="trkpt" Then
        lati = Attributes.GetValue2("","lat")
        'Log(lati)
        loni = Attributes.GetValue2("","lon")
        'Log(loni)
    End If
End Sub

'    Required for parser
Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
    If Name="name" And lati.Length>0 Then
        desc=Text.ToString
        'Log(description)
        Dim Marker As Marker
        Marker.Initialize("Waypoint", desc, lati, loni, Main.Icon)
        Log("Waypoint - " & desc & ", " & lati & " | " & loni)
        gList.Add(Marker)
               
    End If
End Sub

Called from main using:

B4X:
Dim pGPX  As GPXFileToParse
pGPX=GPXParser.Initialise(fd.FilePath, fd.ChosenName, Icon)
GPXParser.wpParse(pGPX)
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Thank you. I've tried something like this but I stopped because I can not find the SaxParser library.
It 'a long time since I'm looking for.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Solved ! (however I can not read the height above sea level, elevation)

B4X:
    Dim In As InputStream
        In = File.OpenInput(File.DirRootExternal,  PercorsoGPS & "/" & NomeTraccia)
        parser.Parse(In, "Parser")
        In.Close
        For i=0 To PathOverlay1.GetNumberOfPoints -1
            Riga=PathOverlay1.GetAllPoints.Get(i)
            ele = Regex.Split(",",Riga)
            Lt=ele(0) : Lg= ele(1) : H= ele(2) * 0.3048
            If Lg>MaxLg Then MaxLg=Lg
            If Lt>MaxLt Then MaxLt=Lt
            If Lg<MinLg Then MinLg=Lg
            If Lt<MinLt Then MinLt=Lt
            If H>MaxAltezzaGPS Then MaxAltezzaGPS=H
            If H<MinAltezzaGPS Then MinAltezzaGPS=H
        Next
        CentroLt=(MaxLt-MinLt)/2+MinLt : CentroLg=(MaxLg-MinLg)/2+MinLg

B4X:
Sub Parser_StartElement (Uri As String, Name As String, Attributes As Attributes)
    If Name="trkpt" Then
        lati = Attributes.GetValue2("","lat")
        loni = Attributes.GetValue2("","lon")
        elevation = Attributes.GetValue2 ("","ele")  ' ???
    If elevation="" Then elevation="0"
    End If
End Sub

Sub Parser_EndElement (Uri As String, Name As String, Text As StringBuilder)
   If Name="trkpt" And lati.Length>0 Then
    Dim P As Location
    P.Initialize
    P.Latitude=lati
    P.Longitude=loni
    P.Altitude=elevation
    PathOverlay1.AddPoint2 (P)   
    End If
End Sub
 
Upvote 0
Top