question: public double signedDistanceToLineSegment ( LatLong A , LatLong B ) { double Ax = ( A . lng - lng ) * Math . cos ( 0.5 * radians * ( A . lat + lat ) ) ; double Ay = ( A . lat - lat ) ; double Bx = ( B . lng - lng ) * Math . cos ( 0.5 * radians * ( B . lat + lat ) ) ; double By = ( B . lat - lat ) ; double Ix = ( ( By - Ay ) * ( Ax * By - Ay * Bx ) ) / ( ( Ax - Bx ) * ( Ax - Bx ) + ( Ay - By ) * ( Ay - By ) ) ; return ( ( Bx - Ax ) * Ay - Ax * ( By - Ay ) ) / Math . sqrt ( ( Bx - Ax ) * ( Bx - Ax ) + ( By - Ay ) * ( By - Ay ) ) * EarthRadius * radians ; }
target:  Similar to above, except that you get a negative value if you're on the left side of this line segment. 