【问题标题】:How to draw a line between points in google map in Android如何在Android中的谷歌地图中的点之间画一条线
【发布时间】:2010-05-31 06:38:23
【问题描述】:

我已经写了一个从安卓 GPS 读取位置的程序;每个 locatin(long , lat) 将被发送到远程服务器保存并显示在网站地图中。

我现在要做的是通过在点之间画线来在 android 中显示我的路径 直到此刻我才找到任何足够的答案!那么如何做到这一点呢?

【问题讨论】:

  • 在地图中,如果您进入菜单 > 实验室,有一个名为“测量”的功能可以让您画线。它是为用户设计的,但也许您可以调查以编程方式对其进行操作
  • Thanx ,但我在 Eclipse 中找不到任何地图选项卡,所以它是 Eclipse 中的一个功能吗?还是另一个叫做地图的程序?

标签: android google-maps path overlay


【解决方案1】:

您可以在点之间画线:

public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when)
        {
        Projection projection = mapView.getProjection();
        if (shadow == false)
        {
      Paint paint = new Paint();
      paint.setAntiAlias(true);
      paint.setColor(Color.BLUE);

      Point point = new Point();
      projection.toPixels(gp1, point);
      /* mode=1 create the starting point */
      if(mode==1)
      {
          RectF oval=new RectF(point.x - mRadius, point.y - mRadius,
                             point.x + mRadius, point.y + mRadius);
        /* draw the circle with the starting point  */
        canvas.drawOval(oval, paint);
      }
      /* mode=2 draw the route line */
      else if(mode==2)
      {
        Point point2 = new Point();
        projection.toPixels(gp2, point2);
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(5);
        paint.setAlpha(120);
        /* draw the lint */
        canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
      }
      /* mode=3 create the ending point */
      else if(mode==3)
      {
        /* draw the line of the last part firstly to avoid error */
        Point point2 = new Point();
        projection.toPixels(gp2, point2);
        paint.setStrokeWidth(5);
        paint.setAlpha(120);
        canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
        /* define the RectF object */
        RectF oval=new RectF(point2.x - mRadius,point2.y - mRadius,
                             point2.x + mRadius,point2.y + mRadius);
        /* draw the circle with the ending point */
        paint.setAlpha(255);
        canvas.drawOval(oval, paint);
      }
    }
    return super.draw(canvas, mapView, shadow, when);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    相关资源
    最近更新 更多