How long is my route actually? When it comes to routing there is one thing that is for sure - there are no rights and wrongs. Routing is indeed an interesting subject.
What length of the route does Bings Direction service provide? I suspect the length is in 2d, not the actual driving distance. So lets find out.
Calculating 3d distance on a sphere is hard. So first I need to narrow it down to something that is understandable for me. So I route between my home town and a ski resort in the mountains.
So lets examine what happens when transforming the coordinates to UTM. Fortunately the route is within the same UTM zone. So for each segment I simple used Pythagoras formula to calculate the length of each segment. It gives me 284.491 km. It gives a difference of 0.25%. Still within what is acceptable for this experiment.
In order to measure in 3d I use the elevations service for each location received from the direction service. After that all I need to do is add the elevation to the location.
Since it is now a planar coordinate system it is now possible to calculate 3d length with Pythagoras formula, according to this: https://math.stackexchange.com/questions/42640/calculate-distance-in-3d-space. The result surprised me though. Given planar conditions it says 284.538. Which is a different of 47 meters.That is a big surprise! I thought it would be more significant.
And comparing my 3d route length with the length from spatial math library it just about 0.01%.
My conclusion is that for driving it is not really worth calculating if it is not in extreme terrain. But for walking and bicycling it makes sense to take elevation into account.
The code is here for scrutiny: https://github.com/perfahlen/how-long-is-my-route