How to draw a line between points in google map in Android

只谈情不闲聊 提交于 2019-12-04 19:43:17

You can draw line between points as:

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);
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!