The distance between two nodes is equal to the simple sum of the distance to the closest nodes. In order to calculate the distance between two nodes, we can use getDistance() method for the same.