我正在构建一个应用程序,它将 GPS 位置存储在 SQLite 数据库中,然后通过在点之间绘制一条红线,使用 Overlay 将数据输出到 MapView。
我希望能够为每个点以及红线显示图形标记(图像)。我的代码如下:
public class MyOverlay extends ItemizedOverlay<OverlayItem> {
// private Projection projection;
private Paint linePaint;
private Vector<GeoPoint> points;
public MyOverlay(Drawable defaultMarker) {
super(defaultMarker);
points = new Vector<GeoPoint>();
//set colour, stroke width etc.
linePaint = new Paint();
linePaint.setARGB(255, 255, 0, 0);
linePaint.setStrokeWidth(3);
linePaint.setDither(true);
linePaint.setStyle(Style.FILL);
linePaint.setAntiAlias(true);
linePaint.setStrokeJoin(Paint.Join.ROUND);
linePaint.setStrokeCap(Paint.Cap.ROUND);
}
public void addPoint(GeoPoint point) {
populate();
points.addElement(point);
}
//public void setProjection(Projection projection) {
// this.projection = projection;
// }
public void draw(Canvas canvas, MapView view, boolean shadow) {
populate();
int size = points.size();
Point lastPoint = new Point();
if(size == 0) return;
view.getProjection().toPixels(points.get(0), lastPoint);
Point point = new Point();
for(int i = 1; i<size; i++){
view.getProjection().toPixels(points.get(i), point);
canvas.drawLine(lastPoint.x, lastPoint.y, point.x, point.y, linePaint);
lastPoint = point;
}
}
@Override
protected OverlayItem createItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}
}
为每个 GeoPoint 添加标记的最简单方法是什么?