I've done something similar.
I've added some markers to a MapView
and afterwards connecting them with a line.
I have a class LineOverlay
which extends Overlay
.
In the constructor it gets the list of items to be connected by lines.
Something like:
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);
}
and then on the onDraw()
I do this:
@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.