I need to draw a Polygon from several points (I have their latitude, longitude). I am basing my implementation from these two answers: Drawing an empty polygon given a set of points on a Map Overylay (Android 2.1) Drawing a line/path on Google Maps
In my MapOverlayAction.java I set the overlay for some pins like this:
mapOverlays.add(itemizedoverlay);
setLocationOverlay(mapView, mapController);
where itemizedoverlay is an array of OverlayItems
This works fine. But I also need to draw a polygon for these points (where each point is a vertex). So what I do is:
Path path = new Path();
for (int j = 0; j < itemizedoverlay.size(); j++) {
GeoPoint gP1 = itemizedoverlay.getItem(j).getPoint();
Point currentScreenPoint = new Point();
Projection projection = mapView.getProjection();
projection.toPixels(gP1, currentScreenPoint);
if (j == 0)
path.moveTo(currentScreenPoint.x, currentScreenPoint.y);
else
path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
}
In both of the answersI am basing my solution, the following method is being called:
Paint mPaint = new Paint();
mPaint.setDither(true);
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(2);
canvas.drawPath(path, mPaint);
My question is, where do I get that canvas from? I have all this code in my activity class.
Thanks!