MapView 中是否有要使用的 Polygon 类?

发布于 2024-12-02 03:10:31 字数 119 浏览 1 评论 0原文

是否有第三方库或 Android 类(例如 google.maps.Polygon)可在 MapView(本机 Google 地图 API)中使用?我用谷歌搜索但找不到它。

Is there a third party lib or Android class like google.maps.Polygon to be used in MapView (Native Google Maps APIs)? I have googled but I couldn't find it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心欲静而疯不止 2024-12-09 03:10:31

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

The is no class for drawing polygons in the Maps API. See documentation here:

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

Below is some code I used to draw a route given a list of points. You could probably modify it to do what you need.

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);
        }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文