Android Question OSMDROID, MapView and traces GPX

Discussion in 'Android Questions' started by AlpVir, May 7, 2016.

  1. AlpVir

    AlpVir Well-Known Member Licensed User

    Use the library OSMDROID and MapView.
    With this simple code I see the traces of PLT type (Oziexplorer).
    Code:
    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.
     
  2. mark35at

    mark35at Well-Known Member Licensed User

    This any help to you?

    Code:
    '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 BitmapDrawableAs 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 StringAttributes 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:

    Code:
    Dim pGPX  As GPXFileToParse
    pGPX=GPXParser.Initialise(fd.FilePath, fd.ChosenName, Icon)
    GPXParser.wpParse(pGPX)
     
  3. AlpVir

    AlpVir Well-Known Member Licensed 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.
     
  4. AlpVir

    AlpVir Well-Known Member Licensed User

    Solved ! (however I can not read the height above sea level, elevation)

    Code:
    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
    Code:
    Sub Parser_StartElement (Uri As String, Name As StringAttributes 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice