I have two location specified in latitude and longitude (A and B). Between these location is a line (Green). I am at a third location (Me). How do I determine how far I am away from this line and in what direction the closest point to it is from where I am (the Gray line)?
I'm looking for heading in degrees and distance in meters. If I can find the location at which the gray line meets the green line then I can use the Android Location built in functions to calculate distance and heading.
Does anybody know given the lat/long locations of A, B and Me how to solve the above problem?
Bear in mind that 'Me' does not know whether he's in the first or second situation and that this is a navigation problem.
Also I would appreciate it if you would also bear in mind that I'm crap at maths and answer like your talking with a 15 year old.
Also, I've worked out an example by hand using Google Earth. So given:
double aLat = 51.44376;
double aLng = -2.86525;
double bLat = 51.43574;
double bLng = -2.87026;
double meLat = 51.4391;
double meLng = -2.86437;
Answer should be:
Distance to closest point on line (aprox): 235 meters
Heading to closest point on line (aprox): 109 degrees
As always, thanks for your help,
Adam