[英]How to draw route using multiple geopoints?
I am implementing an android application for Map activity. 我正在为地图活动实现一个Android应用程序。
I am using Location listener for getting location updates. 我正在使用位置侦听器获取位置更新。 After updating location i am saving those updated latitude and longitude values in database.
更新位置后,我将那些更新的纬度和经度值保存在数据库中。
I am able draw Route path From Source to destination using source latitude, longitude and destination latitude, longitude values. 我可以使用源纬度,经度和目标纬度,经度值绘制从源到目的地的路线路径。 But using multiple latitude and longitude values of database at a time i want to draw the route path.
但是一次要使用多个数据库的经度和纬度值,我想绘制路径。 I am using my RoutePath.java class to draw the route path for multiple latitudes and longitudes .Using those list of latitudes and longitudes i am able to draw the path, but it shows point to point stright line not shows the route path.
我正在使用RoutePath.java类绘制多个纬度和经度的路线路径。使用这些纬度和经度列表,我可以绘制路径,但是它显示的是点对点的直线,而没有显示路线。 See the below image...
见下图...
If you observe carefully some points are on the route and some points are outside of route path. 如果您仔细观察,路线上的某些点和路线路径之外的某些点。 See again below image with full zooming...
再次看到下面的全变焦图片...
Please help me if anyone knows the solution for this problem... 如果有人知道该问题的解决方案,请帮助我。
RoutePath.java: RoutePath.java:
public class RoutePath extends Overlay {
private int _pathColor;
private final List<GeoPoint> _points;
private boolean _drawStartEnd;
public RoutePath(List<GeoPoint> points) {
this(points, Color.RED, true);
}
public RoutePath(List<GeoPoint> points, int pathColor,
boolean drawStartEnd) {
_points = points;
_pathColor = pathColor;
_drawStartEnd = drawStartEnd;
}
private void drawOval(Canvas canvas, Paint paint, Point point) {
Paint ovalPaint = new Paint(paint);
ovalPaint.setStyle(Paint.Style.FILL_AND_STROKE);
ovalPaint.setStrokeWidth(2);
int _radius = 6;
RectF oval = new RectF(point.x - _radius, point.y - _radius, point.x
+ _radius, point.y + _radius);
canvas.drawOval(oval, ovalPaint);
}
public boolean draw(Canvas canvas, MapView mapView, boolean shadow,
long when) {
Projection projection = mapView.getProjection();
if (shadow == false && _points != null) {
Point startPoint = null, endPoint = null;
Path path = new Path();
// We are creating the path
for (int i = 0; i < _points.size(); i++) {
GeoPoint gPointA = _points.get(i);
Point pointA = new Point();
projection.toPixels(gPointA, pointA);
if (i == 0) { // This is the start point
startPoint = pointA;
path.moveTo(pointA.x, pointA.y);
} else {
if (i == _points.size() - 1)// This is the end point
endPoint = pointA;
path.lineTo(pointA.x, pointA.y);
}
}
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(_pathColor);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
paint.setAlpha(90);
if (getDrawStartEnd()) {
if (startPoint != null) {
drawOval(canvas, paint, startPoint);
}
if (endPoint != null) {
drawOval(canvas, paint, endPoint);
}
}
if (!path.isEmpty())
canvas.drawPath(path, paint);
}
return super.draw(canvas, mapView, shadow, when);
}
public boolean getDrawStartEnd() {
return _drawStartEnd;
}
public void setDrawStartEnd(boolean markStartEnd) {
_drawStartEnd = markStartEnd;
}
}
您获得了直线,因为GeoPoints只是这样。.....意味着,如果您具有完整的路线,则它将根据您的Geopoints显示。...这都取决于GeoPoints。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.