我做过类似的事情。我在 a 添加了一些标记,MapView
然后用一条线将它们连接起来。
我有一个LineOverlay
扩展类Overlay
。在构造函数中,它获取要按行连接的项目列表。
就像是:
public LineOverlay(ItemizedOverlay<? extends OverlayItem> itemizedOverlay, int lineColor) {
mItemizedOverlay = itemizedOverlay;
colorRGB = lineColor;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(colorRGB);
mPaint.setStrokeWidth(LINE_WIDTH);
}
然后在onDraw()
我这样做:
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow) {
if ( mItemizedOverlay.size() == 0 || mItemizedOverlay.size() == 1 )
return;
Projection projection = mapView.getProjection();
int i = 0;
while( i < mItemizedOverlay.size() - 1 ){
OverlayItem begin = mItemizedOverlay.getItem(i);
OverlayItem end = mItemizedOverlay.getItem(i+1);
paintLineBetweenStations(begin,end,projection,canvas);
i++;
}
super.draw(canvas, mapView, shadow);
}
private void paintLineBetweenStations(OverlayItem from, OverlayItem to, Projection projection, Canvas canvas){
GeoPoint bPoint = from.getPoint();
GeoPoint ePoint = to.getPoint();
Point bPixel = projection.toPixels(bPoint, null);
Point ePixel = projection.toPixels(ePoint, null);
canvas.drawLine(bPixel.x, bPixel.y, ePixel.x, ePixel.y, mPaint);
}
In your case you can do something similar creating a SubtitleOverlay
which extends Overlay
that receives all items in the constructor and then on the draw
method create a subtitle in the correct position.