public void buildLegs(ArrayList<GeoPoint> waypoints){
  mLegs=new ArrayList<RoadLeg>();
  int firstNodeIndex=0;
  int w=waypoints.size();
  int n=mNodes.size();
  for (int i=1; i < w - 1; i++) {
    GeoPoint waypoint=waypoints.get(i);
    double distanceMin=-1.0;
    int nodeIndexMin=-1;
    for (int j=firstNodeIndex; j < n; j++) {
      GeoPoint roadPoint=mNodes.get(j).mLocation;
      double dSquared=distanceLLSquared(roadPoint,waypoint);
      if (nodeIndexMin == -1 || dSquared < distanceMin) {
        distanceMin=dSquared;
        nodeIndexMin=j;
      }
    }
    RoadLeg leg=new RoadLeg(firstNodeIndex,nodeIndexMin,mNodes);
    mLegs.add(leg);
    firstNodeIndex=nodeIndexMin + 1;
  }
  RoadLeg lastLeg=new RoadLeg(firstNodeIndex,n - 1,mNodes);
  mLegs.add(lastLeg);
}

public void buildLegs ( ArrayList < GeoPoint > waypoints ) { mLegs = new ArrayList < RoadLeg > ( ) ; int firstNodeIndex = 0 ; int w = waypoints . size ( ) ; int n = mNodes . size ( ) ; for ( int i = 1 ; i < w - 1 ; i ++ ) { GeoPoint waypoint = waypoints . get ( i ) ; double distanceMin = - 1.0 ; int nodeIndexMin = - 1 ; for ( int j = firstNodeIndex ; j < n ; j ++ ) { GeoPoint roadPoint = mNodes . get ( j ) . mLocation ; double dSquared = distanceLLSquared ( roadPoint , waypoint ) ; if ( nodeIndexMin == - 1 || dSquared < distanceMin ) { distanceMin = dSquared ; nodeIndexMin = j ; } } RoadLeg leg = new RoadLeg ( firstNodeIndex , nodeIndexMin , mNodes ) ; mLegs . add ( leg ) ; firstNodeIndex = nodeIndexMin + 1 ; } RoadLeg lastLeg = new RoadLeg ( firstNodeIndex , n - 1 , mNodes ) ; mLegs . add ( lastLeg ) ; }
as mapquest and osrm doesn ' t provide legs information , we have to rebuild it , using the waypoints and the road nodes . < br > note that mapquest legs fit well with waypoints , as there is a " dedicated " node for each waypoint . but osrm legs are not precise , as there is no node " dedicated " to waypoints .
