If there is a route you can sort the ways, split it up at a station and then calculate the distance by summing up the lenght of the ways.