# Android Google Maps average polyline paths

I'm making an android app that maps my path through plotting polylines using the google map API. If I have several of these paths, it just looks like a bunch of paths plotted on top of each other. Is there a way, through the Google Maps API to "average" these paths out? I was starting to head down a complicated path of computing the headings (geography util) and using those headings to get nearby polylines with similar headings and then averaging out the lats and lons to draw a polyline that was the average of all of the similar polylines. Before I do that I was wondering if anyone knew of a better way and/or if I should be using polygons instead of polylines? Here's a visual of what I am trying to do (sorry I used paint): I don't know of a function in the googlemap api which would do what you want but I would do it kinda like below. I know that there are of course better ways of doing this but it is a simple way and you don't need the whole heading and bearing calculations.
You have to use the `GoogleMap.getProjection().getProjection().toScreenLocation(LatLng) ` on every visible LatLng Point.

``````List<List<Point>> PointList;
boolean close = false;
int distance = 10;

for(Point actual : PointList.get(0)) {
for(Point check : PointList.get(1)) {
if(check.x < actual.x + distance && check.x > actual.x - distance
&& check.y < actual.y + distance && check.y > actual.y - distance) {
close = true;
} else {
close = false;
break;
}
}
if(!close) {
break;
}
}
if(close) {
PointList.remove(1);
//draw a polyline with thicker stroke and the points from PointList.get(0)
}
``````

This checks if every point in pointlist1 is within a square of a point from pointlist2 independent where the Polyline startet or which directions they went. If your Points are to close together think about a path simplification algorithm like the Ramer–Douglas–Peucker algorithm.

Based on my understanding, you want to merge multi-polylines into one polyline, you may use 'Encoded Polyline Algorithm Format'. Polyline encoding is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values. If you only have a few static points, you may also wish to use the interactive polyline encoding utility.

• so then how would I use a really long string of hundreds of coordinates to merge into one? Is there a way to then reorder points based on location and not timestamp since they would be collected sequentially. Feb 19, 2016 at 18:58