在Google地图中手动绘制路径

时间:2012-09-17 10:47:21

标签: android google-maps

我目前正在做一个包含谷歌地图的Android应用程序。在此地图中,我想在两点之间手动绘制路径。一点是我当前的点,另一点是用户标记的点(通过在overlay类中使用draw方法绘制,代码如下所示)。请帮助我。

 protected class Touchy extends Overlay {

    @Override
    public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
            long when) {
        Paint paint = new Paint();

        super.draw(canvas, mapView, shadow);
        // Converts lat/lng-Point to OUR coordinates on the screen.
        Point myScreenCoords = new Point();
        mapView.getProjection().toPixels(geoPoint, myScreenCoords);

        paint.setStrokeWidth(1);
        paint.setARGB(255, 255, 255, 255);
        paint.setStyle(Paint.Style.STROKE);

        Bitmap bmp = BitmapFactory.decodeResource(getResources(),
                R.drawable.source);

        canvas.drawBitmap(bmp, myScreenCoords.x, myScreenCoords.y, paint);

        for(int i=0;i<size;i++)
        {
            mapView.getProjection().toPixels(GP[i], myScreenCoords);
            canvas.drawBitmap(bmp,myScreenCoords.x, myScreenCoords.y,                        paint);
        }
        return true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent e, final MapView m) {
        // TODO Auto-generated method stub

        System.out.println("Hiiiiiiiiiiiiiiiiiiii");

        if (e.getAction() == MotionEvent.ACTION_DOWN) {
            start = e.getEventTime();
            int x = (int) e.getX();
            int y = (int) e.getY();
            touchedPoint = m.getProjection().fromPixels(x, y);
            System.out.println(touchedPoint);
        }

        if (e.getAction() == MotionEvent.ACTION_UP) {
            stop = e.getEventTime();
        }
        if (stop - start > 1500) {

            AlertDialog alert = new AlertDialog.Builder(
                    LocationTrackerActivity.this).create();
            alert.setTitle("Location Tracker");
            alert.setMessage("Enter your Option");

            alert.setButton("Mark", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    if (FlagPin == 0) {

                        OverlayItem overlayItem = new OverlayItem(
                                touchedPoint, "wazzup", "xd");
                        PinPoint custom = new PinPoint(d,
                                LocationTrackerActivity.this);

                        custom.insertPinpoint(overlayItem);
                        overlayList.add(custom);
                        FlagPin = 1;

                        destLat = touchedPoint.getLatitudeE6() / 1E6;
                        desLong = touchedPoint.getLongitudeE6() / 1E6;



                    }

                }
            });   

1 个答案:

答案 0 :(得分:0)

如果您知道两个地理位置,请按照此链接在这些点之间绘制路径。

http://lokeshatandroid.blogspot.in/2012/09/draw-path-between-two-geo-points.html

您已经知道当前位置GeoPoint并找到用户指示标记的纬度和长值,并按照上述链接。