【发布时间】:2011-05-10 10:50:03
【问题描述】:
我正在从存储它的 ServerManager 类中读取一些 GPS 数据(经度、纬度)。
读取是在后台线程 AsyncTask 中完成的,并且是逐步完成的。每次我得到一个新点时,我都会把它放在地图上,并在它和最后一个表示的点之间画一条线。
这是我的代码的一部分:
地理点 p;
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]));
}
}
}
为了表示我使用的地图上的点:
public void theRouteDraw(GeoPoint p1) {
mc.animateTo(p1);
mc.setZoom(17);
mapView.invalidate();
mapView.setSatellite(true);
}
为了获得我使用的叠加层:
class myOverlay 扩展 Overlay {
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);
}
}
我的问题:
有没有人知道为什么我的地图上没有画线????谢谢你:)
【问题讨论】: