1

I want to draw Driving direction Route from source geopoints to Destination geopoints. I tried this with the below code but its draw a straight line between the Location not proper shortest route.

@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
    // TODO Auto-generated method stub
    super.draw(canvas, mapView, shadow);

    Projection projection = classMapView.getProjection();

     Paint   mPaint = new Paint();
        mPaint.setDither(true);
        mPaint.setColor(Color.RED);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(2);

        GeoPoint gP1 = new GeoPoint(22716221,75896816);
        GeoPoint gP2 = new GeoPoint(22715212, 75895806);

        Point p1 = new Point();
        Point p2 = new Point();

        Path    path = new Path();

        projection.toPixels(gP1, p1);
        projection.toPixels(gP2, p2);

        path.moveTo(p2.x, p2.y);
        path.lineTo(p1.x,p1.y);

        canvas.drawPath(path, mPaint);
}

Please help and also tell me is it possible to get text of direction as Google Maps provide.

2 Answers 2

3

Please go through Google Policies

This states that turn-by- turn navigation is not allowed using android MapView.

instead you can use intent to do that as follows

 Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
 Uri.parse("http://maps.google.com/maps?saddr=<start lat>,<start lon>&daddr=<dest lat>,<dest lon>"));
 startActivity(intent);
2
  • Is there any other way to achieve these. Commented May 9, 2012 at 13:10
  • please check this. But before implementing anything like this, do read section 8 of Google Policies. You cannot use directions without prior permission in android mapView.
    – silwar
    Commented May 9, 2012 at 13:17
2

Here is a complete source code at https://github.com/frogermcs/RoutePathExample for how to draw path between two geolocation.

1
  • @Murat Nafiz not anymore valid link.
    – divy3993
    Commented Dec 5, 2015 at 21:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.