1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question [Solved] Problem draw polyline in OSM

Discussion in 'Android Questions' started by Descartex, Feb 13, 2016.

  1. Descartex

    Descartex Well-Known Member Licensed User

    Hi:
    I'm trying to draw a polyline from a kml file, i've got all the points inside the file using SaxParser.
    That's the code, but it doesn't draw anything and i don't see where is the mistake, var contorno has the points i've inserted.

    Code:
    Sub Globals
    Dim Archivo AsSaxParser
    Dim MapView1 As MapView
    Dim contorno As PathOverlay
    End Sub
    Sub Activity_Create(FirstTime As Boolean)
    IfFile.ExternalWritable=
    False Then
    ' OSMDroid requires the use of external storage to cache tiles' if no external storage is available then the MapView will display no tiles
    Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
    EndIf 
    ' no EventName is required as we don't need to listen for MapView events MapView1.Initialize("")
    Activity.AddView(MapView1, 00100%x100%y' by default the map will zoom in on a double tap and also be draggable - no other user interface features are enabled ' enable the built in zoom controller - the map can now be zoomed in and out 
    MapView1.SetZoomEnabled(True' enable the built in multi touch controller - the map can now be 'pinch zoomed' 
    MapView1.SetMultiTouchEnabled(True' set the zoom level BEFORE the center (otherwise unpredictable map center may be set) 
    MapView1.Zoom=8 MapView1.SetCenter(-11.7464,-75.7672
    contorno.Initialize(MapView1,
    Colors.Red) 
    Archivo.InitializeDim 
    fichero AsInputStream 
    fichero=
    File.OpenInput(File.DirAssets,"file.kml"
    Archivo.Parse(fichero,
    "Etiqueta")
    End Sub

    Sub Etiqueta_EndElement (UriAsString, Name AsString, Text AsStringBuilder)
    'Log(Name)
    If Archivo.Parents.IndexOf("Document") > -1 Then
    If Name = "coordinates" Then
    Dim poly() As String
    Log(Text.ToString) 
    poly=
    Regex.Split(" ",Text.ToString)
    For i=0 To poly.Length-1
    Dim x,y As Double
    Dimpoint() AsString
    point=Regex.Split(",",poly(i))
    Log(point.Length) 
    x=
    point(0
    y=
    point(1)
    Log("x="&x&" y="&y) 
    contorno.AddPoint(x,y)
    Next
    EndIf
    EndIf
    End Sub
    Sub Activity_Resume
    MapView1.AddOverlay(contorno)
    End Sub
    Thanks a lot in advance.
     
  2. eurojam

    eurojam Well-Known Member Licensed User

    Hola Descartes,
    I have tested your code. It is mas o menos ok, but there are some small things missing:
    the initialize of the mapview: MapView1.Initialize("MapView1")
    Tile souce: MapView1.SetTileSource("MapquestOSM")
    the below code based on yours worked, I have only substituted the xmlparsing with a line containing of two points. May be you can start with this...
    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
    Dim Archivo As SaxParser
    Dim MapView1 As MapView
    Dim contorno As PathOverlay
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    If File.ExternalWritable=False Then
      
    ' OSMDroid requires the use of external storage to cache tiles' if no external storage is available then the MapView will display no tiles
      Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
    End If ' no EventName is required as we don't need to listen for MapView events MapView1.Initialize("")
    MapView1.Initialize("MapView1")
    Activity.AddView(MapView1, 00100%x100%y' by default the map will zoom in on a double tap and also be draggable - no other user interface features are enabled ' enable the built in zoom controller - the map can now be zoomed in and out
    MapView1.SetTileSource("MapquestOSM")
    MapView1.SetZoomEnabled(
    True' enable the built in multi touch controller - the map can now be 'pinch zoomed'
    MapView1.SetMultiTouchEnabled(True' set the zoom level BEFORE the center (otherwise unpredictable map center may be set)
    MapView1.Zoom=18
    MapView1.SetCenter(-
    11.7464,-75.7672)


    contorno.Initialize(MapView1,
    Colors.Red)
    contorno.StrokeWidth=
    4

    'Archivo.InitializeDim
    'Dim fichero As InputStream
    'fichero=File.OpenInput(File.DirAssets,"file.kml")
    'Archivo.Parse(fichero,"Etiqueta")
    contorno.AddPoint( -11.7464,-75.7672)
    contorno.AddPoint( -
    11.747,-75.768)
    End Sub

    Sub Activity_Resume
      MapView1.AddOverlay(contorno)
    End Sub
     
    Descartex likes this.
  3. Descartex

    Descartex Well-Known Member Licensed User

    Thanks a lot!!!
    I was obfuscated.
    it worked like a charm.
     
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