1

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

mezo
  • 93
  • 2
  • 9
  • Only draw what the map can see, if you plotting everything is unnecessary since you cant see everything unless you zoom way out on the map – tyczj Jun 04 '18 at 12:38
  • but there is sill a problem when the user zoom out i want to fix it – mezo Jun 04 '18 at 12:57
  • Then the user needs to know that there could be performance issues with zooming out, There is nothing you can do besides restricting how much is plotted on the map. The same issue happens with plotting a lot of markers on a map – tyczj Jun 04 '18 at 13:02
  • so is there is other solution i can use to draw the user path on the map – mezo Jun 04 '18 at 13:13
  • polyline is the only way to draw on a map. Also based on your code I hope you are just adding points to a line and not redrawing all the latlng points over again, that would be a big problem – tyczj Jun 04 '18 at 13:18
  • how can i do that? and i do some research and i found something called TileOverlay do you have any idea if it could help – mezo Jun 04 '18 at 13:20
  • To keep it simple I would just call `mMap.clear()` then replot the line, clear removed everything from the map. if you want something more advanced then google around and you can find how to add to a polyline – tyczj Jun 04 '18 at 13:26

1 Answers1

1

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);
    }
}
mezo
  • 93
  • 2
  • 9