Google map issue for multicolor polyline

Viewed 33

We are drawing polyline according to different zone colors (Different colors assigned to the different zone where the person is in) and the below issue, we are facing constantly. Is anyone know the solution?

[![Firebase logs:][1]][1]

Getting issue on line no 8: polyline.setPoints(points) where points contain array of lat/lng. eg:lat/lng: (34.282619,-119.149895) AlexMamo

 PolylineOptions options = new PolylineOptions();
            Polyline polyline = null;
            for (int i = 1; i < coloredPointArrayLit.size(); i++) {
                if (coloredPointArrayLit.get(i).color == coloredPointArrayLit.get(i - 1).color) {
                    if (polyline != null) {
                        List<LatLng> points = polyline.getPoints();
                        points.add(coloredPointArrayLit.get(i).coordinates);
                        polyline.setPoints(points);
                    } else {
                        options.add(coloredPointArrayLit.get(i - 1).coordinates);
                        options.add(coloredPointArrayLit.get(i).coordinates);
                        options.color(coloredPointArrayLit.get(i).color);
                        options.jointType(JointType.ROUND);
                        options.endCap(roundCap);
                        options.startCap(roundCap);
                        // Add the polyline to the map colored polyline
                        polyline = this.googleMap.addPolyline(options
                                .width(DensityTool.adjustToDensity(context, 7)));
                    }
                } else {
                    options = new PolylineOptions();
                    options.add(coloredPointArrayLit.get(i - 1).coordinates);
                    options.add(coloredPointArrayLit.get(i).coordinates);
                    polyline = null;
                }
            }

Any help will be appreciated.

1 Answers

You are using new PolyLineOptions instance for each and every line you draw to the maps. This is make the drawing slow.

Only use one instance of polyline options and use only the .add(LatLng) function inside the loops.

Please refer this link: https://stackoverflow.com/a/39616306/4896829

Related