I am new to java drawing and I would like to implement a navigation system so a user can navigate on a map. The java function 'onDraw' is implement so it shows the location of the user on the map and also show his movements. Below are my codes:
class CanvasView extends View {
private Paint paint = new Paint();
private Path path = new Path();
private float lineX = Position.x_axis;
private float lineY = Position.y_axis;
private float lastX = Position.x_axis;
private float lastY = Position.y_axis;
public CanvasView(Context context) {
super(context);
paint.setAntiAlias(true);
paint.setStrokeWidth(10f);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
drawRotateImage(canvas);
canvas.drawPoint(Position.x_axis, Position.y_axis, paint);
Path path = new Path();
path.moveTo(lastX, lastY);
path.lineTo(lineX,lineY);
canvas.drawPath(path, paint);
}
private void stepDetector (float step) {
stepCount += (int) step;
distance = stepCount * 30;
lineX = (float) (lineX + 30);
lineY = (float) (lineY + 30);
invalidate();
lastX = lineX;
lastY = lineY;
}
}
The stepdetector is called each time a step has been detected and it should repaint the canvas to show to movements. Noting that the previous movement line needs to be visible, that is it should be a continuous line.
I am having issues to get the navigation line path. It would be grateful if I can get some help on it.
Thank you in advance.