How to dynamically add polylines from an archaist

I have

places = ArrayList<ArrayList<LatLng>> 

I add LatLng points to the internal ArrayList, and then I have a for loop that loops and adds polylines to the map .. besides that it doesn’t do this ... How can I add polylines to GoogleMap dynamically? I checked if the places were filled or not.

Thanks in advance.

 ArrayList<Polyline> pl = new ArrayList<Polyline>(); for(int i =0; i<places.size(); i++){ pl.add(mMap.addPolyline(new PolylineOptions().addAll(places.get(i)))); Log.e("size of places", "size of places is " + places.size()); } 
+4
source share
3 answers

When you have a list of longitude latitudes in your list, you can use the following to draw lines.

 List<LatLng> points = decodePoly(_path); // list of latlng for (int i = 0; i < points.size() - 1; i++) { LatLng src = points.get(i); LatLng dest = points.get(i + 1); // mMap is the Map Object Polyline line = mMap.addPolyline( new PolylineOptions().add( new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude,dest.longitude) ).width(2).color(Color.BLUE).geodesic(true) ); } 

above worked for me in my application

+8
source

Adding multiple points in a map using polyline and arraylist

 ArrayList<LatLng> coordList = new ArrayList<LatLng>(); // Adding points to ArrayList coordList.add(new LatLng(0, 0); coordList.add(new LatLng(1, 1); coordList.add(new LatLng(2, 2); // etc... // Find map fragment. This line work only with support library GoogleMap gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); PolylineOptions polylineOptions = new PolylineOptions(); // Create polyline options with existing LatLng ArrayList polylineOptions.addAll(coordList); polylineOptions .width(5) .color(Color.RED); // Adding multiple points in map using polyline and arraylist gMap.addPolyline(polylineOptions); 
+9
source

What is the places variable, because places must have all the locations in the line, not just one point.

Thus, if the places are ArrayList<LatLng> , then by doing places.get(i) , you specify only one point, not the entire list of points;

0
source

All Articles