Android Question Polyline in Google Map Api v2

Facilauto Juan

Member
Licensed User
Longtime User
Hello there!

I can see the map in my app.
I can see the marker with the "Hello!!!"
But... I can't see the polyline.

What could be happening?

Thanks in advance for your responses.

B4X:
Sub Map_Ready
  Log("map ready")
  gmap = mFragment.GetMap
  If gmap.IsInitialized = False Then
      ToastMessageShow("Error initializing map.", True)
  Else
      gmap.AddMarker(36, 15, "Hello!!!")
      Dim line As Polyline
      Dim points As List
      Dim point As LatLng 
      Dim color() As Int
      linea=gmap.AddPolyline
      points.Initialize
     
      'color=
      line.color=Array As Int(255,255,255)
      line.Geodesic=True
      line.Visible =True
      line.Width=2
      'line.ZIndex=0
      point.Initialize(37.772323, -122.214897)
      points.Add(point)
      point.Initialize(21.291982, -157.821856)
      points.Add(point)
      point.Initialize(-18.142599, 178.431)
      points.Add(point)
      point.Initialize(-27.46758, 153.027892)
      points.Add(point)
      line.Points=points
      Dim cp As CameraPosition
      cp.Initialize(36, 15, gmap.CameraPosition.Zoom)
      gmap.AnimateCamera(cp)
  End If
End Sub
 

eurojam

Well-Known Member
Licensed User
Longtime User
The line goes from California - Hawaii (Aloa...) to fitschi island and ends in Australia, whereas the camera of the maps goes to Malta (Mediterranean Sea). So there will be no line visible. Try to zoom to Hawaii (Aloa...) ...

Cheers
stefan
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
The line goes from California - Hawaii (Aloa...) to fitschi island and ends in Australia, whereas the camera of the maps goes to Malta (Mediterranean Sea). So there will be no line visible. Try to zoom to Hawaii (Aloa...) ...

Cheers
stefan
I zoom but not have any line.event i set width 10 but not draw
 
Upvote 0

eurojam

Well-Known Member
Licensed User
Longtime User
I have tried the example, no problem. The line goes from California via Hawaii (Aloa...) to Australia (I have changed the color from white to red)...
B4X:
Sub Globals
    Dim MapFragment1 As MapFragment
    Dim GoogleMap1 As GoogleMap
    Dim MapPanel As Panel
    'Dim GroundOverlay1 As GroundOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    Else
        MapFragment1.Initialize("MapFragment1", MapPanel)
    End If
End Sub

Sub MapFragment1_Ready
    Log("MapFragment1_Ready")
    Log(MapFragment1.GetOpenSourceLicenseInfo)

    GoogleMap1 = MapFragment1.GetMap
    If GoogleMap1.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    Else

      GoogleMap1.AddMarker(36, 15, "Hello!!!")
      Dim line As Polyline
      Dim points As List
      Dim Point As LatLng
      line=GoogleMap1.AddPolyline
      points.Initialize
    
      'color=
      line.color=Colors.Red 'Array As Int(255,255,255)
      line.Geodesic=True
      line.Visible =True
      line.Width=2
      'line.ZIndex=0
      Point.Initialize(37.772323, -122.214897)
      points.Add(Point)
      Point.Initialize(21.291982, -157.821856)
      points.Add(Point)
      Point.Initialize(-18.142599, 178.431)
      points.Add(Point)
      Point.Initialize(-27.46758, 153.027892)
      points.Add(Point)
      line.points=points
      Dim cp As CameraPosition
      cp.Initialize(36, 15, GoogleMap1.CameraPosition.Zoom)
      GoogleMap1.AnimateCamera(cp)
    End If
End Sub
 
Upvote 0

arnold steger

Member
Licensed User
Longtime User
I whant use add polyline for view a saved route. My data come in a second moment from a txt file.
My code not draw the line. Where may be my problem?

B4X:
        Dim PolylineCoords0() As Double=Array As Double(46.803602,11.773665,46.80388,11.773706,46.804077,11.773733,46.804615,11.773817,46.804894,11.773837000000002)
        Dim PolylinePoints0 As List=CoordsToLatLngList0(PolylineCoords0)
        PolylinePoints0.Initialize
       
        Dim Polyline0 As Polyline
        Polyline0=gmap.AddPolyline
        Polyline0.Points=PolylinePoints0
        Polyline0.Width=4
        Polyline0.Color=gmap.HUE_YELLOW
        Polyline0.Geodesic=True
        Polyline0.Visible=True
               
        Dim StartLat,StartLng As Double
        StartLat=PolylineCoords0(0)
        StartLng=PolylineCoords0(1)
       
        Dim cp As CameraPosition
     cp.Initialize(StartLat,StartLng, 15)
     gmap.AnimateCamera(cp)
 
Upvote 0

BarryW

Active Member
Licensed User
Longtime User

This code only show a straight line... How to get the path of the roads
 
Upvote 0

arnold steger

Member
Licensed User
Longtime User
The part of read from file currently i have not maked.I must first decide what format is the best for my use. I can post when it run.
 
Upvote 0

arnold steger

Member
Licensed User
Longtime User
i have added in my code the part of read from txt. not draw the line.
not finde my problem.
B4X:
        Dim listtemp,listpoints As List
       
        listpoints.Initialize
        listtemp = File.ReadList(File.DirAssets,"route_1.txt")
        For i = 0 To listtemp.Size-1
        Dim Punkte() As String = Regex.Split(",",listtemp.Get(i))
            Dim ln As LatLng
            ln.Initialize(Punkte(0),Punkte(1))
            listpoints.Add(ln)
        Next
       
        Dim Polyline0 As Polyline
        Polyline0=gmap.AddPolyline
        Polyline0.Points.Addall(listpoints)
        Polyline0.Width=4
        Polyline0.Color=Colors.White
        Polyline0.Geodesic=True
        Polyline0.Visible=True
the listpoints fill fine
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…