Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw smooth line between geopoints on android

I've drawed line between geopoints. its successfully drawed. when we see the map, the drawline look like pixelated when adjecent of next drawling. how to merge the line?

enter image description here

My code is here,

@Override
public void draw(Canvas canvas, MapView mapview, boolean shadow) {
    super.draw(canvas, mapview, shadow);
    if(! routeIsActive) return;

    mapview.getProjection().toPixels(locpoint, pp);       // Converts GeoPoint to screen pixels

    int xoff = 0;
    int yoff = 0;
    int oldx = pp.x;
    int oldy = pp.y;
    int newx = oldx + xoff;
    int newy = oldy + yoff;

    paint.setAntiAlias(true);
    paint.setDither(true);
            paint.setStrokeWidth(7);
    for(int i=0; i<numberRoutePoints-1; i++)
    {
        switch(routeMode.get(i))
        {
        case 0:
            paint.setColor(Color.parseColor("#666666"));
            break;
        case 1:
            paint.setColor(Color.parseColor("#0EA7D6"));
            break;
        case 2:
            paint.setColor(Color.parseColor("#654321"));
            break;
        case 3:
            paint.setColor(Color.parseColor("#123456"));
            break;
        }   

        mapview.getProjection().toPixels(routePoints.get(i), pold);
        oldx = pold.x;
        oldy = pold.y;
        mapview.getProjection().toPixels(routePoints.get(i+1), pnew);
        newx = pnew.x;
        newy = pnew.y;

        canvas.drawLine(oldx, oldy, newx, newy, paint);
    }

}
like image 662
RVG Avatar asked Jul 27 '12 12:07

RVG


2 Answers

You should change the style of the paint object like this:

paint.setStrokeCap(Cap.ROUND);
like image 122
Andy Res Avatar answered Nov 15 '22 05:11

Andy Res


If you draw a circle at the beginning and the end of each line (the circle diameter must be the line height), I think it will do the trick or maybe drawRoundRect of the canvas can do it well

like image 20
VinceFR Avatar answered Nov 15 '22 03:11

VinceFR