gpt4 book ai didi

android - 在谷歌地图上画一条线/路径

转载 作者:IT老高 更新时间:2023-10-28 13:03:15 29 4
gpt4 key购买 nike

我一直忙于寻找如何在 HelloMapView 中的 map 上的两个 (GPS) 点之间画一条线,但没有运气。

谁能告诉我怎么做。

假设我使用扩展 MapView 的 HelloMapView。我需要使用叠加层吗?如果是这样,我是否必须覆盖叠加层的 onDraw() 方法并在这里画一条线?我实际上尝试了这些东西,但没有结果。

提前谢谢你!

最佳答案

感谢您的帮助。我终于可以在 map 上画一条线了。我就是这样做的:

/** 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 projection=mapv.getProjection();
projection.toPixels(gP1, p1);
projection.toPixels(gP2, p2);

path.moveTo(p2.x, p2.y);
path.lineTo(p1.x,p1.y);

canvas.drawPath(path, mPaint);
}

关于android - 在谷歌地图上画一条线/路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2176397/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com