2011-05-09 74 views
1

使用Android的谷歌地圖的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); 

} 

所以如果我想刪除路徑1的讚揚路徑刪除!幫助請

回答

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」爲真,並呼籲View.Invalidate強制視圖重繪當你想。刪除路徑,將「drawPath」設置爲false並調用View.Invalidate。

+0

我會嘗試此修復 – exequielc 2014-04-11 22:55:53