绘制线谷歌地图不起作用,谷歌地图Android上的第一个计时器

时间:2012-12-11 06:19:47

标签: android google-maps

我正试图在谷歌地图上的2个地理点之间画一条线。我可以放置标记,但不能在它们之间画一条线。我知道我错过了一些微不足道的事情。

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

编辑:我甚至尝试过

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

1 个答案:

答案 0 :(得分:0)

琐碎错误,没有正确创建GeoPoints

GeoPoint gP1 = new GeoPoint((int)(slat * 1E6),(int) (slng * 1E6));
GeoPoint gP2 = new GeoPoint((int)(dlat * 1E6),(int) (dlng * 1E6));