i am creating a user tracker project , and what i want to do is to draw the user path on the map , the method that i used it's Polyline and this is the code
public void drawOnMap(ArrayList<LatLng> directionPoints) {
PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.GREEN).geodesic(false);
rectLine.addAll(directionPoints);
mMap.addPolyline(rectLine);
}
but after about 500 polyline the map going to laggy and after 1900 the app crash
so is there is better solution
i found a solution and this is the right code
private Polyline polyline;
public void drawOnMap(ArrayList<LatLng> directionPoints) {
if(polyline == null)
{
PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.GREEN).geodesic(false);
rectLine.addAll(directionPoints);
polyline = mMap.addPolyline(rectLine);
}else{
polyline.setPoints(directionPoints);
}
}