I am not sure if this should be an answer or comment. But since I can not write comments, I will write an answer.
This page is a great source for calculating distances. In this case, you are probably looking for a code to calculate a new position when moving along a rail line from a given position. Quote from the page:
lat/lon tc, d (lat1, lon1) ( !):
lat= lat1+d*cos(tc)
IF (abs(lat) > pi/2) "d too large. You can't go this far along this rhumb line!"
IF (abs(lat-lat1) < sqrt(TOL))
{
q=cos(lat1)
}
ELSE
{
dphi=log(tan(lat/2+pi/4)/tan(lat1/2+pi/4))
q= (lat-lat1)/dphi
}
dlon=-d*sin(tc)/q
lon=mod(lon1+dlon+pi,2*pi)-pi
- , . , , . , .