路径删除||删除Google地图的行

时间:2011-05-09 22:43:20

标签: android

使用Android Google地图GPS,并制作路径  enter code here

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
                long when) {
            super.draw(canvas, mapView, shadow);


    GeoPoint p = new GeoPoint((int) (29.987574219703674 * 1E6),
            (int) (31.44225418567575 * 1E6));
    GeoPoint p2 = new GeoPoint((int) ( 29.98763859272003 * 1E6),
            (int) (31.44235074520111 * 1E6));
    GeoPoint p3 = new GeoPoint((int) (29.98718498160553* 1E6),
            (int) (31.442527770996094 * 1E6));
    GeoPoint p4= new GeoPoint((int) (29.98739718380868 * 1E6),
        (int) (31.442527770886084 * 1E6));

    // Let's assume you've assigned values to these two GeoPoints now.

    Projection projection = mapView.getProjection();
    Point startingPoint = projection.toPixels(p, null);

    Point endingPoint = projection.toPixels(p2, null);

    // Create the path containing the line between the two points.
    Path path = new Path();
    path.moveTo(startingPoint.x, startingPoint.y);
    path.lineTo(endingPoint.x, endingPoint.y);

    // Setup the paint. You'd probably do this outside of the draw() method
    // to be more efficient.
    Paint paint = new Paint();
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.RED);


    super.draw(canvas, mapView, shadow);
    // el super de 3shnnn to addd koloooo overlay w path
    canvas.drawPath(path, paint);

}

那么,如果我想删除Path1,删除路径的推荐!请帮助

1 个答案:

答案 0 :(得分:2)

一个选项是创建一个名为“drawPath”的布尔值。将所有用于绘制路径的逻辑放在if语句中:

public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
        super.draw(canvas, mapView, shadow);
   if(drawPath){
       // path drawing logic goes here
   }
}

然后,当您想绘制路径时,将“drawPath”设置为true并调用View.Invalidate以强制视图重绘。如果要删除路径,请将“drawPath”设置为false并调用View。无效。