public ArrayList<Direction> directionsTo(int toNodeId, boolean walkOnly, int fromNodeId) {
    Node fromNode = mGraph.getNode(fromNodeId);
    if (fromNode.getOutGoingEdges().size() == 0) return null;
    GeoPoint fromLoc = new GeoPoint(fromNode.getLatE6(), fromNode.getLongE6());

    return directionsTo(toNodeId, walkOnly, fromLoc);
  }
  public void centerOn(int nodeId, long delayMilliSecs) {
    if (loadMapTask.isCompleted == false) {
      this.mToBeCenterOn = true;
      this.mCenterOnNodeId = nodeId;
      this.mCenterOnDelay = delayMilliSecs;
      return;
    }

    Node node = mGraph.getNode(nodeId);
    GeoPoint loc = new GeoPoint(node.getLatE6(), node.getLongE6());
    centerOn(loc, delayMilliSecs);
  }
 public void routeTo(int toNodeId, boolean walkOnly, int fromNodeId, boolean centerMap) {
   if (!this.loadMapTask.isCompleted) {
     this.isPathToBeDisplayed = true;
     this.destinationNodeId = toNodeId;
     this.startNodeId = fromNodeId;
     this.isWalkOnly = walkOnly;
     Toast.makeText(mContext, ("Please wait for data to load."), Toast.LENGTH_LONG).show();
     return;
   }
   Node fromNode = mGraph.getNode(fromNodeId);
   GeoPoint fromLoc = new GeoPoint(fromNode.getLatE6(), fromNode.getLongE6());
   routeTo(toNodeId, walkOnly, fromLoc, centerMap);
 }
  public ArrayList<Direction> getDirectionsFromEdges(ArrayList<Edge> pathData) {
    if (pathData == null || pathData.size() == 0) return null;
    Node n;
    Edge edge;
    ArrayList<Direction> directions = new ArrayList<Direction>();
    int currentType = Edge.TYPE_WALK;
    Direction direction = null;

    int prevEdgeType = -1;
    String title = "";
    for (int i = 0; i < pathData.size(); i++) {
      try {
        edge = pathData.get(i);
        if (edge.getEdgeType() == Edge.TYPE_WAIT) {
          // special case: if the final destination is a bus/tram stop
          // we add a final indicator for destination node
          if (i == (pathData.size() - 1)) { // last edge. must display destination
            n = edge.getToNode();
            direction = new Direction(edge, "Reach destination at " + n.getTitle());
            directions.add(direction);
            direction.setFrom(edge.getFromNodeTitle());
            LogHelper.d("2359", "Edge: Direction added: " + "Reach destination at " + n.getTitle());
            break;
          }

          if (edge.getCostForEdge() > 0) title = edge.getFromNode().getTitle();
          continue;
        }

        if (i == 0) { // first edge. must display start point
          currentType = edge.getEdgeType();
          n = edge.getFromNode();
          if (n.getTitle() != null) title = n.getTitle();
          String descText = edge.getLineName();
          if (edge.getEdgeType() == Edge.TYPE_WALK) {
            if (edge.getCostForEdge() == Edge.DUMMY_EDGE_COST)
              descText = "Walk from your starting location";
            else descText = descText.replace("Alight", "Start").replace("#NODE_NAME#", title);
          } else {
            descText =
                descText
                    .replace("Board", "Start at " + title + " and board")
                    .replace("#NODE_NAME#", "");
          }
          direction = new Direction(edge, descText);
          directions.add(direction);
          direction.setFrom(edge.getFromNodeTitle());
          LogHelper.d("2359", "Edge: Direction added: " + descText);

        } else {
          if (edge.getEdgeType() != currentType) {
            // if there is a change in the type of edge
            currentType = edge.getEdgeType();
            n = edge.getFromNode();
            if (n.getTitle() != null) title = n.getTitle();
            String descText = edge.getLineName();
            if (prevEdgeType != Edge.TYPE_WALK && edge.getEdgeType() != Edge.TYPE_WALK)
              descText = descText.replace("Board", "Alight and change to");
            descText = descText.replace("#NODE_NAME#", title);
            direction = new Direction(edge, descText);
            directions.add(direction);
            direction.setFrom(edge.getFromNodeTitle());
            LogHelper.d("2359", "Edge: Direction added: " + descText);
          }
        }

        // add a final indicator for destination node
        if (i == (pathData.size() - 1)) { // last edge. must display destination
          n = edge.getToNode();
          direction = new Direction(edge, "Reach destination at " + n.getTitle());
          directions.add(direction);
          direction.setFrom(edge.getFromNodeTitle());
          LogHelper.d("2359", "Edge: Direction added: " + "Reach destination at " + n.getTitle());
        }

        prevEdgeType = edge.getEdgeType();

        float results[] = {0};
        Location.distanceBetween(
            edge.getFromNode().getLatE6() / 1E6,
            edge.getFromNode().getLongE6() / 1E6,
            edge.getToNode().getLatE6() / 1E6,
            edge.getToNode().getLongE6() / 1E6,
            results);

        LogHelper.d(
            "2359",
            "Edge: From:"
                + edge.getFromNodeTitle()
                + ", To: "
                + edge.getToNodeTitle()
                + ", Type: "
                + edge.getLineLabel()
                + ", Distance: "
                + results[0]
                + " m");
        if (direction != null) {
          direction.setDistance(direction.getDistance() + results[0]);
          direction.setTo(edge.getToNodeTitle());
          if (edge.getEdgeType() != Edge.TYPE_WAIT && edge.getEdgeType() != Edge.TYPE_WALK) {
            direction.setStops(direction.getStops() + 1);
          }
        }
      } catch (Exception ignore) {
        ignore.printStackTrace();
      }
    }
    return directions;
  }
  ///////////////////// THIS IS TO DISPLAY PATH WHEN A* ALGORITHM DETERMINES THE
  // PATH/////////////////////////////
  public void showPathForEdges(ArrayList<Edge> pathData) {
    if (pathData == null || pathData.size() == 0) return;

    // HERE WE OBTAIN THE POINTS WHICH TOGETHER REPRESENT THE PATH
    pathPointList.clear();
    ArrayList<GeoPoint> edgeContourList;
    int color = 0;
    Edge edge;

    for (int i = (pathData.size() - 1); i >= 0; i--) {
      edge = pathData.get(i);
      color = edge.getEdgeColor();
      pathPointList.add(
          new PathPoint(
              edge.getToNode().getLatE6(),
              edge.getToNode().getLongE6(),
              color)); // this is the destination node's coords

      edgeContourList = edge.getEdgeContourList(mContext.getContentResolver());
      if (edgeContourList != null) {
        for (GeoPoint p : edgeContourList) {
          pathPointList.add(new PathPoint(p.getLatitudeE6(), p.getLongitudeE6(), color));
        }
      }

      if (i == 0) {
        // add the data of the first point of the first node
        pathPointList.add(
            new PathPoint(edge.getFromNode().getLatE6(), edge.getFromNode().getLongE6(), color));
      }
    }

    // HERE WE GET THE PATH INDICATORS LIST
    pathIndicatorList.clear();
    pathIndicatorOverlays.removeAllItems();
    Node n;
    int currentType = Edge.TYPE_WALK;
    Resources r = mapView.getResources();
    int indicatorCount = 0;
    int prevEdgeType = -1;
    String title = "";
    for (int i = 0; i < pathData.size(); i++) {
      try {
        edge = pathData.get(i);

        if (edge.getEdgeType() == Edge.TYPE_WAIT) {
          // special case: if the final destination is a bus/tram stop
          // we add a final indicator for destination node
          if (i == (pathData.size() - 1)) { // last edge. must display destination
            n = edge.getToNode();
            indicatorCount++;
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    "Reach destination at " + n.getTitle(),
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
            break;
          }

          if (edge.getCostForEdge() > 0) title = edge.getFromNode().getTitle();
          continue;
        }

        if (i == 0) { // first edge. must display start point
          currentType = edge.getEdgeType();
          n = edge.getFromNode();
          if (n.getTitle() != null) title = n.getTitle();
          indicatorCount++;
          String descText = edge.getLineName();
          if (edge.getEdgeType() == Edge.TYPE_WALK) {
            if (edge.getCostForEdge() == Edge.DUMMY_EDGE_COST)
              descText = "Walk from your starting location";
            else descText = descText.replace("Alight", "Start").replace("#NODE_NAME#", title);
          } else {
            descText =
                descText
                    .replace("Board", "Start at " + title + " and board")
                    .replace("#NODE_NAME#", "");
          }

          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  descText,
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        } else {
          if (edge.getEdgeType() != currentType) {
            // if there is a change in the type of edge
            currentType = edge.getEdgeType();
            n = edge.getFromNode();
            if (n.getTitle() != null) title = n.getTitle();
            indicatorCount++;
            String descText = edge.getLineName();
            if (prevEdgeType != Edge.TYPE_WALK && edge.getEdgeType() != Edge.TYPE_WALK)
              descText = descText.replace("Board", "Alight and change to");
            descText = descText.replace("#NODE_NAME#", title);
            OverlayItem item =
                new OverlayItem(
                    indicatorCount + ":path_indicator" + n.getID(),
                    null,
                    descText,
                    n.getGeoPoint(),
                    DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
            item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
            pathIndicatorOverlays.addItem(item);
          }
        }

        // add a final indicator for destination node
        if (i == (pathData.size() - 1)) { // last edge. must display destination
          n = edge.getToNode();
          indicatorCount++;
          OverlayItem item =
              new OverlayItem(
                  indicatorCount + ":path_indicator" + n.getID(),
                  null,
                  "Reach destination at " + n.getTitle(),
                  n.getGeoPoint(),
                  DrawableUtils.numberedPathDirectionDrawable(r, indicatorCount));
          item.setMarkerHotspot(HotspotPlace.BOTTOM_CENTER);
          pathIndicatorOverlays.addItem(item);
        }

        prevEdgeType = edge.getEdgeType();
      } catch (Exception ignore) {
        ignore.printStackTrace();
      }
    }

    pathOverlay.setPoints(pathPointList);
    mapView.postInvalidate();
  }