public void OnGetDistanceDocumentComplete(Document doc, int i, int j) {
    int distance = md.getDistanceValue(doc);
    adj[i][j] = distance;
    docAdj[i][j] = doc;

    if ((vertices.size() * vertices.size()) - vertices.size() == counter.incrementAndGet()) {
      findOptimalPath();
    }
  }
  public void showOptimalPath(Document doc) {
    ArrayList<LatLng> directionPoint = md.getDirection(doc);
    PolylineOptions rectLine = new PolylineOptions().width(8).color(Color.BLUE);

    for (int i = 0; i < directionPoint.size(); i++) {
      rectLine.add(directionPoint.get(i));
    }
    googleMap.addPolyline(rectLine);
  }
 private void generateAdjacencyMatrix() {
   for (int i = 0; i < vertices.size(); i++) {
     for (int j = 0; j < vertices.size(); j++) {
       if (i != j) {
         if (adj[i][j] == 0) {
           md.getDocument(
               new LatLng(vertices.get(i).getLatitude(), vertices.get(i).getLongitude()),
               new LatLng(vertices.get(j).getLatitude(), vertices.get(j).getLongitude()),
               GMapV2Direction.MODE_DRIVING,
               this,
               i,
               j);
         }
       }
     }
   }
 }