I'm having a hard time wrapping my head around some Trigonometry. I am trying to deduce a destination latitude and longitude from a start lat and log and distance and bearing.
Fortunately, I found an amazing site which describes exactly the function I need: http://www.movable-type.co.uk/scripts/latlong.html " Destination point given distance and bearing from start point " I tried it in my java program but it is not working for me. I deployed it as the website said. Here is my code:
double dist = 150/6371; double brng = Math.toRadians(90); double lat1 = Math.toRadians(26.88288045572338); double lon1 = Math.toRadians(75.78369140625); double lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist) + Math.cos(lat1)*Math.sin(dist)*Math.cos(brng) ); double a = Math.atan2(Math.sin(brng)*Math.sin(dist)*Math.cos(lat1), Math.cos(dist)-Math.sin(lat1)*Math.sin(lat2)); System.out.println("a = " + a); double lon2 = lon1 + a; lon2 = (lon2+ 3*Math.PI) % (2*Math.PI) - Math.PI; System.out.println("Latitude = "+Math.toDegrees(lat2)+"\nLongitude = "+Math.toDegrees(lon2));
But it shows the output is:
a = 0.0 Latitude = 26.882880455723377 Longitude = 75.78369140625
I am not getting where i am doing the mistake. Please anybody can help me to find out the problem.
Thanx in Advance. :-)