如何画点之间的直线谷歌在Android的地图 [英] How to draw a line between points in google map in Android
本文介绍了如何画点之间的直线谷歌在Android的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经写了读安卓GPS位置的程序;每个locatin(长,纬度)将被发送到远程服务器,以将其保存在一个网站地图显示它。
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?
推荐答案
您可以画点之间的线路为:
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);
}
这篇关于如何画点之间的直线谷歌在Android的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文