Android Question Drawing Polyline on Google Map -- Nothing Shows

touchsquid

Active Member
Licensed User
Longtime User
B4X:
Sub LineTest
    'Dim gmap As GoogleMap (in globals
    'Wait For Gmap1_Ready (in activity_create
    'gmap = Gmap1.GetMap
    Dim GME As GoogleMapsExtras
    gmap.Clear
    
    Dim Pt1 As LatLng
    Pt1.Initialize(49.3,-123.5)
    Dim Pt2 As LatLng
    Pt2.Initialize(49.5,-123.0)
    gmap.AddMarker2(Pt1.Latitude,Pt1.Longitude,"Test1",gmap.HUE_GREEN)
    gmap.AddMarker2(Pt2.Latitude,Pt2.Longitude,"Test2",gmap.HUE_GREEN)
    
    Dim SL As PolylineOptions
    SL.Initialize
    SL.Add(Pt1)
    SL.Add(Pt2)
    
    Dim sPoly As Polyline =GME.AddPolyline(gmap, SL)
    sPoly.Color=gmap.HUE_GREEN
    sPoly.Width = 15dip
    Dim LLB As LatLngBoundsBuilder
    LLB.Initialize
    LLB.Include(Pt1)
    LLB.Include(Pt2)
    
    Dim LatLngBounds1 As LatLngBounds = LLB.Build
    GME.AnimateToBounds2 (gmap, LatLngBounds1 , Activity.Width,Activity.height, 50)
End Sub

The above code compiles and runs without error. The Markers appear on the map and it zooms and pans to the area. BUT, the polyline does not show. This is a subset of a longer path I have tried to draw with no results. Is there some special permission to draw lines?

Otherwise the map is working fine. I have examined other code in the forum and tried several variations but nothing draws a visible line.

Any help is greatly appreciated.
 

touchsquid

Active Member
Licensed User
Longtime User
B4X:
Sub LineTest
    'Dim gmap As GoogleMap (in globals
    'Wait For Gmap1_Ready (in activity_create
    'gmap = Gmap1.GetMap
    gmap.Clear
    
    Dim Pt1 As LatLng
    Pt1.Initialize(49.3,-123.5)
    Dim Pt2 As LatLng
    Pt2.Initialize(49.5,-123.0)
    gmap.AddMarker2(Pt1.Latitude,Pt1.Longitude,"Test1",gmap.HUE_GREEN)
    gmap.AddMarker2(Pt2.Latitude,Pt2.Longitude,"Test2",gmap.HUE_GREEN)
    
    
    Dim sPoly As Polyline = gmap.AddPolyline
    sPoly.Points.Add(Pt1)
    sPoly.Points.Add(Pt2)
    sPoly.Color=gmap.HUE_GREEN
    sPoly.Width = 15dip
    Dim LLB As LatLngBoundsBuilder
    LLB.Initialize
    LLB.Include(Pt1)
    LLB.Include(Pt2)
    
    Dim LatLngBounds1 As LatLngBounds = LLB.Build
    GME.AnimateToBounds2 (gmap, LatLngBounds1 , Activity.Width,Activity.height, 50)
End Sub

This is where I originally started. Again the marks appear in the right places, but no polyline. I can't see any error in the code, but no line appears.

Any ideas?
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
This Code works:
Dim sPoly As PolylineOptions
    sPoly.Initialize
    Dim l As List
    l.Initialize
    l.Add(Pt1)
    l.Add(Pt2)
    sPoly.AddPoints(l)
    myPolyline = GME.AddPolyline(gmap, sPoly)
    myPolyline.Width = 4dip
    myPolyline.Color = Colors.Red

When I add an intermediate list as shown above it works. I don't see why, but I will just do it!
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
Turns out, nothing wrong with my original code except using the sPoly.Color=gmap.HUE_GREEN.
If I use sPoly.Color=colors.green, the line appears!
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
See

Polyline
B4X:
    Dim PolylineOptions1 As PolylineOptions
    PolylineOptions1.Initialize
    PolylineOptions1.AddPoints(PointList)
    PolylineOptions1.Color = Colors.Blue
    PolylineOptions1.Width = 6
    PolylineOptions1.Visible = True
    PolylineOptions1.ZIndex = 3
 
    Dim Polyline1 As Polyline
    Polyline1 = GoogleMapsExtras1.AddPolyline(GoogleMap1, PolylineOptions1)
Polygon
B4X:
    Dim PolygonOptions1 As PolygonOptions
    PolygonOptions1.Initialize
    PolygonOptions1.AddPoints(PointList)
    PolygonOptions1.FillColor = Colors.ARGB(150,255,255,0)
    PolygonOptions1.StrokeColor = Colors.DarkGray
    PolygonOptions1.StrokeWidth = 3
    PolygonOptions1.Visible = True
    PolygonOptions1.ZIndex = 3
 
    Dim Polygon1 As Polygon
    Polygon1  = GoogleMapsExtras1.AddPolygon(GoogleMap1, PolygonOptions1)
Circle
B4X:
    Dim CircleOptions1 As CircleOptions
    CircleOptions1.Initialize
    CircleOptions1.Center2(Latitude, Longitude)
    CircleOptions1.Radius(300)
    CircleOptions1.FillColor(Colors.Green)
    CircleOptions1.StrokeColor(Colors.Red)
    CircleOptions1.StrokeWidth(4)
    CircleOptions1.Visible(True)
    CircleOptions1.ZIndex(3)
   
    Dim Circle1 As Circle
    Circle1 = GoogleMapsExtras1.AddCircle(GoogleMap1, CircleOptions1)
1646344445750.png
 
Last edited:
Upvote 0
Top