0

我需要使用谷歌地图在 Android 应用程序上绘制路线。我有一个 LatLngs 列表,我必须从客户那里使用,不幸的是,这不是所有 lats 和 longs 的完整列表,而是来自 web 服务的一部分,所以我正在尝试遍历从 web 服务获得的所有航点列表并绘制一个使用这些点的正确路线。不幸的是,这只会在航路点或 LatLng 之间画一条直线。关于如何迭代并绘制这条路线的任何建议?

我的代码:

private void showEvacuationRoute(List<LatLng> latlngList){
    LatLng currentLoc = null;
    PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED);
    for (LatLng latLng : latlngList){



        for (int i = 0; i < latlngList.size() - 1; i++) {
            if (i % 2 == 0){
                currentLoc = new LatLng(latLng.latitude, latLng.longitude);


            } else {
                LatLng toPostion = new LatLng(latLng.latitude, latLng.longitude);
                GMapV2Direction md = new GMapV2Direction();
                Document doc = md.getDocument(currentLoc, toPostion, GMapV2Direction.MODE_DRIVING);
                ArrayList<LatLng> directionPoint = md.getDirection(doc);



                for(int j = 0 ; j < directionPoint.size() ; j++) {          
                    rectLine.add(directionPoint.get(j));
                }



            }
        }

    }
    if (!(rectLine == null)){
        map.addPolyline(rectLine);
    }

}
4

0 回答 0