【发布时间】:2011-11-09 00:04:09
【问题描述】:
我需要从几个点绘制一个多边形(我有它们的纬度,经度)。 我的实现基于这两个答案: Drawing an empty polygon given a set of points on a Map Overylay (Android 2.1) Drawing a line/path on Google Maps
在我的 MapOverlayAction.java 中,我为一些图钉设置了覆盖,如下所示:
mapOverlays.add(itemizedoverlay);
setLocationOverlay(mapView, mapController);
其中 itemizedoverlay 是一个 OverlayItems 数组
这很好用。但我还需要为这些点绘制一个多边形(每个点都是一个顶点)。所以我要做的是:
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);
}
在这两个答案中,我的解决方案都基于以下方法:
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);
我的问题是,我从哪里得到画布? 我的活动类中有所有这些代码。
谢谢!
【问题讨论】:
标签: android canvas android-mapview android-maps