0

如何在不同的 GPS 坐标之间画线以将它们连接在一起?

我应该提一下,这不是一条路线。我正在使用卫星视图,例如,这条线可以越过一所房子。

4

1 回答 1

0

如果它只是两个坐标,而不是在地图上绘制一个简单的画布并在这些坐标之间绘制一条直线,那么它将是一条简单的线,它可以在任何地方绘制,甚至在房子上。

下面的示例代码是 在谷歌地图上绘制一条线/路径

/** 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);
}
于 2013-01-24T20:16:39.153 回答