Identifying series of coordinates. I have two coordinates(latitude,longitude) which is defining line on the map. The line has direction. Then I have series of other coordinates moving either roughly along this line and towards direction or opposite direction. Also they can cross the line, etc. The important part is that I need to identify only the case when series of points are moving along and towards direction. Those series are coordinates from gps. Let's also define threshold in meters for identifying that point "belongs" to line. This will include gps error and line error.
I am looking for some formula which I could apply to each point, then after applying twice I can identify direction and continue until end of the line. Below is drawing (sorry for finger quality), hopefully demonstrating what I mean.

Green dots are series which are moving towards line direction. They are what we need to identify. Top blue dots are series moving opposite direction. Also want to emphasize that those lines are not really lines and maybe we need to consider their roundness.
 A: A geodesic on a sphere correspond to the intersection of that sphere with a plane through its origin. So instead of talking about a line on a sphere, you could just as well talk about a plane. The plane would be defined by your two defining points together with the origin. You could determine its normal vector by computing the cross product of the two defining points. Normalizing this normal vector leads you to the Hesse normal form of the plane which you can use to compute distance from the line. OK, it will really be distance form the plane, but unless your acceptance range is really large, this will make almost no difference.
To identify the direction traveled between two points, you can computetheir cross product, and then the scalar product of that vector with the normal vector of your plane. The result will be positive if the movement was in the direction of the line, and negative otherwise. If you get all your cross products ordered consistently, that is, otherwise the signs flip.
My use of cross products implies that you're converting from polar coordinates on the sphere to Cartesian coordinates in 3D.
