简体   繁体   English

如何使用多个地理位置绘制路线?

[英]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.

相关问题 如何在Flutter上的两个地理位置之间绘制路线? - How can I draw a route between two geopoints on the Flutter? 在GoogleMap SupportMapFragment上的2个GeoPoint之间绘制行驶路线 - Draw driving route between 2 GeoPoints on GoogleMap SupportMapFragment 在Android MapView中的多个GeoPoints之间动态绘制线条 - Dynamically draw lines between multiple GeoPoints in Android MapView 如何在Android的Google地图中的两个地理位置(不特定)之间绘制路径? - how to draw a path between two geopoints(not specific) in google map in android? 如何在Android中的地图上的地理点之间绘制虚线? - How to draw dotted lines between geopoints on map in android? 如何使用Intent Android绘制路线图 - how to draw route map using intent Android 如何使用javascript在谷歌地图中的多个标记之间绘制路线图 - How to draw Route map between multiple markers in google maps using javascript 如何在多个LatLong Android地图之间绘制路线? - How to draw route between multiple LatLong Android map? 如何在谷歌地图API Android上使用多个通孔点绘制路线 - How to draw route with multiple via point on google map api android 如何通过 GoogleMaps 上的多个点绘制从 A 到 B 的路线? - How to draw route from A to B through multiple points on GoogleMaps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM