0

I have a requirement to draw out a route on a Android App using google maps. I have a list of LatLngs that I must use from the customer unfortunately this is not a complete list of all lats and longs but a partial from a webservice so I am trying iterate through the list of all waypoints I get from the webservice and draw a correct route that uses these points. Unfortunately this will just draw a straight line between waypoints or LatLng's. Any suggestions on how I could iterate through this and draw this route?

My Code:

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);
    }

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
yams
  • 942
  • 6
  • 27
  • 60

0 Answers0