0

I am trying to draw a line between 2 geopoints on a google map. I am able to place markers, but not draw a line between them. I know I am missing something trivial.

//subscribedToMap is a MapView
subscribedToMap.getOverlays().add(new PathMarker(journey.getSourceGPSX(),
                    journey.getSourceGPSY(),
                    journey.getDestinationGPSX(),
                    journey.getDestinationGPSY())) ;
subscribedToMap.invalidate();

public class PathMarker extends Overlay {
    private Double slat, slng, dlat, dlng;

    public PathMarker(Double slat, Double slng, Double dlat, Double dlng) {
        super();
        this.slat = slat;
        this.slng = slng;
        this.dlat = dlat;
        this.dlng = dlng;
    }

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        canvas.drawLine(slat.intValue(), slng.intValue(), dlat.intValue(),
                dlng.intValue(), new Paint());
        super.draw(canvas, mapView, shadow);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) {
        return (super.onTouchEvent(event, mapView));
    }
}

Edit : I even tried

 public void draw(Canvas canvas, MapView mapv, boolean shadow){
    super.draw(canvas, mapv, shadow);

    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(19240000,-99120000);
    GeoPoint gP2 = new GeoPoint(37423157, -122085008);

    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);
}
4

1 回答 1

0

微不足道的错误,没有正确创建 GeoPoints

GeoPoint gP1 = new GeoPoint((int)(slat * 1E6),(int) (slng * 1E6));
GeoPoint gP2 = new GeoPoint((int)(dlat * 1E6),(int) (dlng * 1E6));
于 2012-12-11T07:30:04.367 回答