May be this can help you
http://www.movable-type.co.uk/scripts/latlong.html
Assuming the start, end, and current position are from GPS, one thing to bear in mind is that GPS can be off a bit, so you may want to do this so that it's not on a line, but instead near the line, with a margin of error.
I have an app where I save off GPS locations and actually show this kind of thing graphically, On the screen shot, the blue circle is where I started, the yellow circles are GPS locations I saved, and the green dot is my current location. If I want to go from one place to another, I just make sure my position follows the of the lines.
The solution is on that page. It is in the section entitled Cross-track distance.
I have a followup question on this. If I want to know the bearing I need to mov to get to the line on this shortest distance....
Can't you just calculate a new bearing using your existing code to calculate the bearing from the current position to the target?