在Google地图中的坐标之间绘制路线

发布于 2024-11-28 16:15:05 字数 67 浏览 2 评论 0原文

谁能告诉我在谷歌地图中的坐标之间画线的简单方法?

我在谷歌中找到了一些结果,但我正在寻找一些简单的东西。

Can anyone show me the simple method to draw a line between coordinates in the Google map?

I found some results in Google, but I am looking for something which is simple.

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

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

发布评论

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

评论(1

海的爱人是光 2024-12-05 16:15:05

使用这个简单的代码...可能适用于您的应用程序

public class GPSLine extends MapActivity {

    private List<Overlay> mapOverlays;
    private Projection projection;
    MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setClickable(true);

        mapOverlays = mapView.getOverlays();
        projection = mapView.getProjection();
        mapOverlays.add(new MyOverlay(null));

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }


    class MyOverlay extends ItemizedOverlay {

        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
        public MyOverlay(Drawable defaultMarker) {
            super(defaultMarker);
            // TODO Auto-generated constructor stub
        }
        @Override
        public void draw(Canvas canvas, MapView mapv, boolean shadow){
            super.draw(canvas, mapv, shadow);

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

            GeoPoint gP1 = new GeoPoint(19240000,-99120000);
            GeoPoint gP2 = new GeoPoint(37423157, -122085008);

            Point p1 = new Point();
            Point p2 = new Point();

        Path path = new Path();

            projection.toPixels(gP1, p1);
            projection.toPixels(gP2, p2);

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

            canvas.drawPath(path, mPaint);
        }
        @Override
        protected OverlayItem createItem(int i) {
            // TODO Auto-generated method stub
            return mOverlays.get(i);
        }
        @Override
        public int size() {
            // TODO Auto-generated method stub
            return 0;
        }
    }
}

use this simple code...may be work in your application

public class GPSLine extends MapActivity {

    private List<Overlay> mapOverlays;
    private Projection projection;
    MapView mapView;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mapView = (MapView) findViewById(R.id.mapview);
        mapView.setBuiltInZoomControls(true);
        mapView.setClickable(true);

        mapOverlays = mapView.getOverlays();
        projection = mapView.getProjection();
        mapOverlays.add(new MyOverlay(null));

    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }


    class MyOverlay extends ItemizedOverlay {

        private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
        public MyOverlay(Drawable defaultMarker) {
            super(defaultMarker);
            // TODO Auto-generated constructor stub
        }
        @Override
        public void draw(Canvas canvas, MapView mapv, boolean shadow){
            super.draw(canvas, mapv, shadow);

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

            GeoPoint gP1 = new GeoPoint(19240000,-99120000);
            GeoPoint gP2 = new GeoPoint(37423157, -122085008);

            Point p1 = new Point();
            Point p2 = new Point();

        Path path = new Path();

            projection.toPixels(gP1, p1);
            projection.toPixels(gP2, p2);

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

            canvas.drawPath(path, mPaint);
        }
        @Override
        protected OverlayItem createItem(int i) {
            // TODO Auto-generated method stub
            return mOverlays.get(i);
        }
        @Override
        public int size() {
            // TODO Auto-generated method stub
            return 0;
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文