Background
I am developing an application that displays a map path (Google maps and OpenStreet maps). The following is an example output:

To draw the above path, I use the following approach:
private void drawWithoutElevation(Canvas canvas, Projection projection){ if(rebuildRequired) pathBuild(); else{
The above approach takes about 1.5ms to draw 10,000 points, which is acceptable.
However, I also want to show the path using different colors depending on the height of the point. The following is an example output:

Since I could not find a way to define different colors for each segment of the path, I tried the following approaches:
Approach 1
The most obvious solution using canvas.drawLine() between each waypoint. Example below:
private void drawWithElevation(Canvas canvas, Projection projection){ for(int i=1; i<geoArrList.size(); i++){ paint.setColor(geoArrList.get(i)); canvas.drawLine(pPrev.x, pPrev.y, p1.x, p1.y, paint); pPrev.set(p1.x, p1.y); } } }
This leads to a very disappointing time of about 80 ms for the same 10,000 points.
Approach 2
Segment the height in discrete steps and create a list of Path objects, one per height change. Sample code below:
private void drawWithElevation(Canvas canvas, Projection projection){ if(rebuildRequired) pathBuild(); for(int i=0; i<pathSegments.size(); i++){ if(needOffset){ pathSegments.get(i).path.offset(offsetX, offsetY); } paint.setColor(pathSegments.get(i).color); canvas.drawPath(pathSegments.get(i).path, paint); } }
This leads to a less disappointing time of about 5 ms for the same 10,000 points.
Question
Although the latter approach shows significant improvement over the first, I would like to improve it even more.
Is there any other approach that could be used to draw paths with different colors per segment in a more efficient way (speed and / or memory usage)?
Thanks for your time and your help.