I am trying to build a GPS app which can show directions between 2 places. For decoding the polylines I am using code from here: Decoding Polylines from Google Maps Direction API with Java. I want to show my route more accurately than this, I am able to do that through kml but it works for very small distances only after which file size reaches limit. Here is screenshot for Boston-Seattle where lines on the map do not follow road but intersect roads

Here is how I am using directions API
public void drawRoute(String source, String destination)
{
String strURL = "http://maps.google.com/maps/api/directions/xml?origin=" + source +
"&destination=" + destination + "&sensor=false&mode=driving";
String url = strURL.replace(" ", "%20");
HttpGet get = new HttpGet(url);
String strResult = "";
try {
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, 3000);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse httpResponse = null;
httpResponse = httpClient.execute(get);
if (httpResponse.getStatusLine().getStatusCode() == 200){
strResult = EntityUtils.toString(httpResponse.getEntity());
}
}
catch (Exception e){ }
if (-1 == strResult.indexOf("<status>OK</status>")){
this.finish();
return;
}
int pos = strResult.indexOf("<overview_polyline>");
pos = strResult.indexOf("<points>", pos + 1);
int pos2 = strResult.indexOf("</points>", pos);
strResult = strResult.substring(pos + 8, pos2);
List<GeoPoint> points = decodePoly(strResult);
RouteOverlay mOverlay = new RouteOverlay(points);
overlayList.add(mOverlay);
if (points.size() >= 2){
controller.animateTo(points.get(0));
}
map.invalidate();
}
Here is my RouteOverlay class:
public class RouteOverlay extends Overlay{
private List<GeoPoint> points;
private Paint paint;
public RouteOverlay(List<GeoPoint> points) {
this.points = points;
paint = new Paint();
paint.setColor(Color.BLUE);
paint.setAlpha(150);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
paint.setStrokeWidth(4);
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
if (!shadow)
{
Projection projection = mapView.getProjection();
if (points != null && points.size() >= 2)
{
Point start = new Point();
projection.toPixels(points.get(0), start);
for (int i = 1; i < points.size(); i++)
{
Point end = new Point();
projection.toPixels(points.get(i), end);
canvas.drawLine(start.x, start.y, end.x, end.y, paint);
start = end;
}
}
}
}
}
Refer this link to draw driving path in your application. You just need to add the four classes present in the link in your project and call the below lines when you need to display the route.
//Also add the permission to your manifeast file