I am a little bit confused since everything seems to be alright with the code. The problem is that the polyline won't show up on the map.
Here is the function that I call to place polyline everytime I receive a location
(I added markers in a similar way and they work great)
private void addPolylineLocationOnMap(LatLng newLoc)
{
PolylineOptions poly = new PolylineOptions()
.add(newLoc)
.color(Color.BLUE)
.width(5)
.visible(true)
.zIndex(30);
googleMap.addPolyline(poly);
}
A
Polyline
needs multiple points!For example, pass an
ArrayList<LatLng>
to your method and useaddAll()
rather than justadd()
.From the
PolylineOptions
documentation:Alternatively, you can keep a reference to one
Polyline
and useadd()
to add points to it as you receive them.Add poly as an instance variable in your class:
Then in
onCreate()
(or wherever you set up the map):Then as you receive more points: