是否在MapView中使用了Polygon类?

时间:2011-08-30 12:56:13

标签: android android-mapview

是否有google.maps.Polygon(原生Google Maps API)中使用的第三方lib或Android类MapView?我用谷歌搜索但我找不到它。

1 个答案:

答案 0 :(得分:1)

在Maps API中没有用于绘制多边形的类。请参阅此处的文档:

http://code.google.com/android/add-ons/google-apis/reference/index.html

以下是我用于绘制路线的一些代码,给出了一个点列表。你可以修改它来做你需要的。

public class MapOverlay extends Overlay {

        ArrayList<GeoPoint> route;

        public MapOverlay(ArrayList<ParcelableGeoPoint> r) {
                route = new ArrayList<GeoPoint>();
                for (ParcelableGeoPoint p: r) {
                        route.add(p.getGeoPoint());
                }
        }

        public void draw(Canvas canvas, MapView mapv, boolean shadow) {
                super.draw(canvas, mapv, shadow);

                Paint mPaint = new Paint();
                mPaint.setDither(true);
                mPaint.setColor(Color.rgb(128, 136, 231));
                mPaint.setAlpha(100);
                mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
                mPaint.setStrokeJoin(Paint.Join.ROUND);
                mPaint.setStrokeCap(Paint.Cap.ROUND);
                mPaint.setStrokeWidth(6);

                Path path = new Path();

                GeoPoint start = route.get(0);
                for (int i = 1; i < route.size(); ++i) {
                        Point p1 = new Point();
                        Point p2 = new Point();

                        Projection projection = mapv.getProjection();
                        projection.toPixels(start, p1);
                        projection.toPixels(route.get(i), p2);

                        path.moveTo(p2.x, p2.y);
                        path.lineTo(p1.x, p1.y);

                        start = route.get(i);
                }
                canvas.drawPath(path, mPaint);
        }
}