I'm building a geo-aware iPhone app and I would like to calculate the distance between the user's location and a line between two points. I found this answer that does something like this:
Shortest distance between a point and a line segment
However this doesn't take into account that the line is finite - if the user is far away from the line but near where an infinite projection of the line would be, it would come out as the distance between the point and the infinite projection, rather than the nearest point on the line.