2013-01-24 184 views
0

怎樣繪製不同的GPS之間的線座標,它們全部連接在一起?畫直線座標

我應該指出,這不是一個路徑。我正在使用衛星視圖,例如,該線路可以通過房屋。

回答

0

如果它只有兩個座標相比怎麼樣繪製在地圖上一個簡單的畫布和繪圖的座標之間的直線上,所以這將是一個簡單的線條,它可以是任何畫在任何地方,甚至在一所房子。

下面的示例代碼被送往 Drawing a line/path on Google Maps

/** Called when the activity is first created. */ 
private List<Overlay> mapOverlays; 

private Projection projection; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

linearLayout = (LinearLayout) findViewById(R.id.zoomview); 
mapView = (MapView) findViewById(R.id.mapview); 
mapView.setBuiltInZoomControls(true); 

mapOverlays = mapView.getOverlays();   
projection = mapView.getProjection(); 
mapOverlays.add(new MyOverlay());   

} 

@Override 
protected boolean isRouteDisplayed() { 
return false; 
} 

class MyOverlay extends Overlay{ 

public MyOverlay(){ 

} 

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

不幸的是它不是2個座標..比這更.. 30,也許 – Blubar

+0

看看示例代碼我已經加入 –

+0

你知道我怎麼能爲此設置一個按鈕?當我按下那個按鈕時,它顯示這一個? – Blubar