Adding visible "Markers" to represent Geopoints to a MapView using ItemizedOverlay in Android

Posted by LordSnoutimus on Stack Overflow See other posts from Stack Overflow or by LordSnoutimus
Published on 2010-03-31T17:33:56Z Indexed on 2010/03/31 18:33 UTC
Read the original article Hit count: 757

Filed under:
|
|
|
|

Hello,

I am building an application which stores GPS locations in a SQLite database and then outputs the data onto a MapView using an Overlay by drawing a red line between the points.

I want to be able to show graphical markers (images) for each of these points as well as the red line. My code is as follows:

public class MyOverlay extends ItemizedOverlay {

// private Projection projection; private Paint linePaint; private Vector 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;
}

}

What would be the easiest way to implement adding markers for each GeoPoint?

Thanks

© Stack Overflow or respective owner

Related posts about android

Related posts about mapview