1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > android对图片拉线测量 如何在谷歌地图上绘制线条叠加Android

android对图片拉线测量 如何在谷歌地图上绘制线条叠加Android

时间:2023-12-04 13:19:25

相关推荐

android对图片拉线测量 如何在谷歌地图上绘制线条叠加Android

我想在我的地图项目上绘制一条线,但无法绘制线条。我在哪里以及如何声明覆盖图?我尝试了各种方法,但无法让它工作。即代码只是在Eclipse中显示错误。我不想做的是画一条从A到B的路线,而是在我移动时绘制路线。如何在谷歌地图上绘制线条叠加Android

// Creating a MapView

public class Gpstrack extends MapActivity {

private MapView map;

private MapController controller;

private Projection projection;

ArrayList geoPointsArray = new ArrayList();

/** 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);

}

}

}

-04-26

sKwok12

+1

什么是错误告诉我们你的日志猫。 –

-04-26 06:47:22

+0

这不是一个输出错误,它是说“方法添加(叠加)类型列表不适用于论据(boolen) –

-04-26 16:23:13

+0

我认为你应该实现位置更改侦听器 –

-04-27 06:26:09

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。