gpt4 book ai didi

android - 如何在 Google map Android 上绘制一条叠加层

转载 作者:太空狗 更新时间:2023-10-29 14:27:45 25 4
gpt4 key购买 nike

我想在我的 map 项目上画一条线,但无法绘制。我在哪里以及如何声明叠加层?我尝试了各种方法,但无法正常工作。即,代码仅在 Eclipse 中显示错误。我不想做的是画一条从 A 到 B 的路线,而是在我移动时画出路线。

// Creating a MapView
public class Gpstrack extends MapActivity {
private MapView map;
private MapController controller;
private Projection projection;
ArrayList<GeoPoint> geoPointsArray = new ArrayList<GeoPoint>();

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);

initMapView();
initMyLocation();


TabHost.TabSpec spec;

TabHost th = (TabHost)findViewById(R.id.tabhost);
th.setup();

spec = th.newTabSpec("tag1");
spec.setContent(R.id.map_Tab);
spec.setIndicator("Map");
th.addTab(spec);

spec = th.newTabSpec("tag2");
spec.setContent(R.id.log_Tab);
spec.setIndicator("Log");
th.addTab(spec);

spec = th.newTabSpec("tag3");
spec.setContent(R.id.details_Tab);
spec.setIndicator("Details");
th.addTab(spec);

spec = th.newTabSpec("tag4");
spec.setContent(R.id.student_Tab);
spec.setIndicator("Student Info");
th.addTab(spec);

}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}

//Map and Controls
private void initMapView() {
map = (MapView) findViewById(R.id.mvMain);
controller = map.getController();
map.setSatellite(true);
//map.setStreetView(true);
map.setBuiltInZoomControls(true);
}


//Creates an Overlay that marks current position
private void initMyLocation() {
final MyLocationOverlay overlay = new MyLocationOverlay(this, map);

overlay.enableMyLocation();
overlay.enableCompass();
overlay.runOnFirstFix(new Runnable() {
public void run() {
controller.setZoom(17);
controller.animateTo(overlay.getMyLocation());
map.getOverlays().add(overlay);



}

});

}


//Experiment
class MyOverlay extends Overlay {
public void draw(Canvas canvas, MapView mapv, boolean shadow) {
super.draw(canvas, mapv, shadow);
Projection projection = mapv.getProjection();
Path p = new Path();



for (int i = 0; i < geoPointsArray.size(); i++) {
if (i == geoPointsArray.size() -1) {
break;
}
Point from = new Point();
Point to = new Point();
projection.toPixels(geoPointsArray.get(i), from);
projection.toPixels(geoPointsArray.get(i + 1), to);
p.moveTo(from.x, from.y);
p.lineTo(to.x, to.y);
}

Paint mPaint = new Paint();
mPaint.setStyle(Style.STROKE);
mPaint.setColor(Color.GREEN);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(5);
canvas.drawPath(p, mPaint);
mapv.invalidate();
super.draw(canvas, mapv, shadow);


}
}
}

最佳答案

你试过用这个演示来实现Google Map Overlay吗? ?

关于android - 如何在 Google map Android 上绘制一条叠加层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10327086/

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