I have a json file with coordinates and putting them in LatLng array. Some coordinates are missing because device is only sending coordinates if it's turned on. So when you turn off device and put it some where else polyline goes through whole map to another point and connect it. I need to somehow split polyline if the distance between two points gets too big. Drawing many polylines for each connecting point is not an option, because there can be 500000 points.
Can not post images here because I don't have reputation.
https://i.stack.imgur.com/Yrcfy.jpg
This is how I put coordinates inside polyline options.
mapData.routeOptions here is equal to polyline options.
List<LatLng> route = new ArrayList<LatLng>();
route.addAll(positions);
double totalDistance=0;
if (route.size() > 1) {
mapData.color = suppliedMapData.color;
int color = mapData.color;
int colorAlpha = Utils.adjustAlpha(color, ROUTE_TRANSPERENCY_PERCENTAGE);
LatLngBounds.Builder boundsBuilder = LatLngBounds.builder();
for (LatLng position : route) {
boundsBuilder.include(position);
}
mapData.routeBounds = boundsBuilder.build();
mapData.routeOptions = new PolylineOptions().addAll(route).color(colorAlpha);
This is how I draw polyline.
int size = sArray.size();
for (int i = 0; i < size; i++) {
MapData mapData = sArray.valueAt(i);
if (mapData.routeOptions != null) {
mapData.routeOptions.width(7);
mPolylines.add(mMap.addPolyline(mapData.routeOptions));
hasPosData = true;
}}
Polylines are added to mPolylines array. because there are more devices than one and all off them need to be drawn.