我移动时如何绘制根路径?

时间:2012-09-25 04:49:42

标签: android google-maps

我正在使用Google地图实施应用。当应用程序进入前台时,我将获得当前位置lat,long和地图上的推针。 但我要求当我移动时,我想根据我的动作绘制根路径。 如果有人知道解决方案,请帮助我。

提前致谢。

1 个答案:

答案 0 :(得分:1)

您是否尝试过扩展Overlay

的课程
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);
}

以这种方式使用:

private List<Overlay> mapOverlays;
private Projection projection;  

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

希望这有帮助!