mezo
mezo

Reputation: 93

android Polyline going to lag the map after while

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

Upvotes: 1

Views: 692

Answers (1)

mezo
mezo

Reputation: 93

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);
    }
}

Upvotes: 1

Related Questions