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

可紊 提交于 2019-12-13 12:19:31

问题


I already wrote a program that read locations from android GPS ; each locatin(long , lat) will be sent to remote server to save it and display it in a website map.

what I'm trying to do now is to display my path in android by drawing line between the points I didn't find any sufficient answer until this moment! so how this can be done?


回答1:


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


来源:https://stackoverflow.com/questions/2941792/how-to-draw-a-line-between-points-in-google-map-in-android

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