jcrowson
jcrowson

Reputation: 4290

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

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<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;
}
}

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

Upvotes: 1

Views: 2847

Answers (1)

AndroidRef.com
AndroidRef.com

Reputation: 326

Take a look at http://www.vtgroup.com/index.html#MapLocation and see if it answers your question.

Upvotes: 2

Related Questions