1
votes

I am implementing an android application for Map activity.

I am using Location listener for getting location updates. After updating location i am saving those updated latitude and longitude values in database.

I am able draw Route path From Source to destination using source latitude, longitude and destination latitude, longitude values. But using multiple latitude and longitude values of database at a time i want to draw the route path. I am using my RoutePath.java class to draw the route path for multiple latitudes and longitudes.Using those list of latitudes and longitudes i am able to draw the path, but it shows point to point stright line not shows the route path. See the below image...

enter image description here

If you observe carefully some points are on the route and some points are outside of route path. See again below image with full zooming...

enter image description here

Please help me if anyone knows the solution for this problem...

RoutePath.java:

public class RoutePath extends Overlay {

    private int _pathColor;
    private final List<GeoPoint> _points;
    private boolean _drawStartEnd;

    public RoutePath(List<GeoPoint> points) {
        this(points, Color.RED, true);
    }

    public RoutePath(List<GeoPoint> points, int pathColor,
            boolean drawStartEnd) {
        _points = points;
        _pathColor = pathColor;
        _drawStartEnd = drawStartEnd;
    }

    private void drawOval(Canvas canvas, Paint paint, Point point) {
        Paint ovalPaint = new Paint(paint);
        ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        ovalPaint.setStrokeWidth(2);
        int _radius = 6;
        RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x
                + _radius, point.y + _radius);
        canvas.drawOval(oval, ovalPaint);
    }

    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
        Projection projection = mapView.getProjection();
        if (shadow == false && _points != null) {
            Point startPoint = null, endPoint = null;
            Path path = new Path();
            // We are creating the path
            for (int i = 0; i < _points.size(); i++) {
                GeoPoint gPointA = _points.get(i);
                Point pointA = new Point();
                projection.toPixels(gPointA, pointA);
                if (i == 0) { // This is the start point
                    startPoint = pointA;
                    path.moveTo(pointA.x, pointA.y);
                } else {
                    if (i == _points.size() - 1)// This is the end point
                        endPoint = pointA;
                    path.lineTo(pointA.x, pointA.y);
                }
            }

            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(_pathColor);
            paint.setStyle(Paint.Style.STROKE);
            paint.setStrokeWidth(5);
            paint.setAlpha(90);
            if (getDrawStartEnd()) {
                if (startPoint != null) {
                    drawOval(canvas, paint, startPoint);
                }
                if (endPoint != null) {
                    drawOval(canvas, paint, endPoint);
                }
            }
            if (!path.isEmpty())
                canvas.drawPath(path, paint);
        }
        return super.draw(canvas, mapView, shadow, when);
    }

    public boolean getDrawStartEnd() {
        return _drawStartEnd;
    }

    public void setDrawStartEnd(boolean markStartEnd) {
        _drawStartEnd = markStartEnd;
        }
    }
1
I don't really understand your question but is this what you are looking for? google-developers.appspot.com/maps/documentation/javascript/… - Chanckjh
Yes am doing this way of stright line. But i want to draw the route path not stright line as showing above link - Hareesh

1 Answers

0
votes

You got Straight line because the the GeoPoints are like that only..... means if you have a complete route paths then it will show according to your Geopoints....It all depends on GeoPoints.!