'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