Android 分散地试图在地图上画一条线
我正在从存储GPS数据的ServerManager类读取一些GPS数据(经度、纬度) 阅读是在后台线程任务中完成的,并且是一步一步地完成的。每次我得到一个新的点,我把它放在地图上,我在它和最后一个点之间画一条线 以下是我代码的一部分: 地质点pAndroid 分散地试图在地图上画一条线,android,map,paint,Android,Map,Paint,我正在从存储GPS数据的ServerManager类读取一些GPS数据(经度、纬度) 阅读是在后台线程任务中完成的,并且是一步一步地完成的。每次我得到一个新的点,我把它放在地图上,我在它和最后一个点之间画一条线 以下是我代码的一部分: 地质点p protected Void doInBackground(Void... voids) { try { while (true) { longitude = Integer.parseInt(Serv
protected Void doInBackground(Void... voids) {
try {
while (true) {
longitude = Integer.parseInt(ServerManager.getInstance()
.getLastLongitude());
latitude = Integer.parseInt(ServerManager.getInstance()
.getLastLatitude());
Log.d("Date citite de threadul AsyncTask", " ");
System.out.println(longitude);
System.out.println(latitude);
p = new GeoPoint(longitude, latitude);
publishProgress(p);
Thread.sleep(500);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onProgressUpdate(GeoPoint... progress1) {
theRouteDraw(progress1[0]);
geoPointsArray.add(progress1[0]);
if (geoPointsArray.size() > 2) {
int length = geoPointsArray.size();
mapView.getOverlays().add(
new myOverlay(geoPointsArray.get(length - 1),
progress1[0]));
}
}
}
为了表示地图上的点,我使用:
公共道路绘制(地质点p1){
}
为了获得覆盖,我使用: 类myOverlay扩展覆盖{
GeoPoint gp1;
GeoPoint gp2;
public myOverlay(GeoPoint gp1, GeoPoint gp2) {
this.gp1 = gp1;
this.gp2 = gp2;
}
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
super.draw(canvas, mapView, shadow);
Paint mPaint = new Paint();
mPaint.setStyle(Style.STROKE);
mPaint.setColor(Color.GREEN);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(4);
Projection projection = mapView.getProjection();
Point from = new Point();
projection.toPixels(gp1, from);
Point to = new Point();
projection.toPixels(gp2, to);
canvas.drawLine(from.x, from.y, to.x, to.y, mPaint);
}
}
我的问题:
有人知道为什么我的地图上没有画线吗???谢谢:)试试这个:
class myLocOverlay extends Overlay { public myLocOverlay(GeoPoint gp1,GeoPoint gp2) {
this.gp1 = gp1;
this.gp2 = gp2;
}
并使用以下命令更新onDraw函数
Paint paint = new Paint(); Point point = new Point();
projection.toPixels(gp1, point); Point point2 = new Point();
projection.toPixels(gp2, point2); canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
可以从活动类中添加地质点
mMapView01.getOverlays().add(new MyOverLay(startGP,endGP));
@阿德里安:若你们并没有收到任何错误信息,那个么检查你们的覆盖类和它的绘图函数,检查它们是否正确调用。试着使用断点并检查日志猫
mMapView01.getOverlays().add(new MyOverLay(startGP,endGP));