2

我正在使用谷歌地图实现一个应用程序。当应用程序进入前台时,我会在地图上获得当前位置 lat、long 和 push pin。但是我要求当我移动时,我想根据我的移动绘制一条根路径。如果有人知道解决方案,请帮助我。

提前致谢。

4

1 回答 1

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());      

希望这可以帮助!

于 2012-09-25T06:51:37.203 回答