How to draw a line between points in google map in Android
I already wrote a program that开发者_StackOverflow社区 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?
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);
}
精彩评论