0

I need to calculate the target coordinate by using the initial coordinate, bearing angle and distance. I came across this on how to calculate it. Then I construct the code in C#, but it seems I can't get exact location correctly. I use below code this my answer:

Target latitude :6.34374176458679
Target longitude : 206.297566445544

When I use the application from the website i mention it get this:

Destination point:  03° 10′ 28″ N, 103° 08′ 15″ E /Lat:3.174444° Lon:103.150833°
Final bearing:  040° 24′ 37″

That are most accurate. Has anybody used this kind of method?

EDIT:

        //bearing angle 
        double rad = 40.41;
        rad *= Math.PI / 180;

        //angDist = distance/radius
        double angDist = 0.717 / 6371;

        Console.WriteLine("Angular distance:" + angDist);

        double latitude =  3.169416;
        double longitude = 103.146690;

        latitude *= Math.PI / 180;
        longitude *= Math.PI / 180;

        double lat2 = Math.Asin(Math.Sin(latitude)*Math.Cos(angDist)+Math.Cos(latitude)*Math.Sin(angDist)*Math.Cos(rad));

        double forAtana = Math.Sin(rad) * Math.Sin(angDist) * Math.Cos(latitude);
        double forAtanb = Math.Cos(angDist)-Math.Sin(latitude)*Math.Sin(lat2);

        double lon2 = longitude + Math.Atan2(forAtana,forAtanb);


        double finalLat = latitude + lat2;
        double finalLon = longitude + lon2;

        finalLat *=  180 / Math.PI;
        finalLon *=  180 / Math.PI;

        Console.WriteLine("Target latitude :" + finalLat);

        Console.WriteLine("Target longitude : " + finalLon);

        // supposely final answer should be Lat:3.174444° Lon:103.150833° (using the movable-type website)


        Console.ReadKey();
  • Your code is using 6378137 (ellipsoid semi-major axis), not 6371000 (sphere radius). – mkennedy Feb 20 '19 at 18:13
  • @mkennedy i edit the code using 6371 km (sphere radius) but still i dont get the same value as i the application on this website. – Mohamad Fathin Feb 21 '19 at 2:16
1

I think that you are adding lat1 (decimal degrees) + lat2 (radians).

lat2 and lon2 are final latitude and longitude in radians. Just convert them to degrees.

UPDATE: I don't know the language, but must to be something like:

double finalLat = lat2 * 180 / Math.PI;  
double finalLon = lon2 * 180 / Math.PI;

Console.WriteLine("Target latitude : " + finalLat); 
Console.WriteLine("Target longitude : " + finalLon); 

(Also, they are using Radius = 6371 km.)

  • I just correct the comment you give. I use radius 6371 km, but it still not get the exact target coordinate. I get this result Target latitude :6.34374176458679 Target longitude : 206.297566445544. – Mohamad Fathin Feb 20 '19 at 8:04
  • I just update my answer to be a bit more explicit. – Gabriel De Luca Feb 20 '19 at 10:11
  • i already edit my code, but the final lat/lon value still far from the result i got using the application on this website. – Mohamad Fathin Feb 21 '19 at 2:18
  • Because you are adding them, don't add. lat2 is the final latitude. lon2 is the final longitude. – Gabriel De Luca Feb 21 '19 at 2:19
  • Thank you very much sir, i get the target coordinate. – Mohamad Fathin Feb 21 '19 at 2:33
0

This final code that will get the target point by using initial coordinate, bearing angle to target point and distance. I get this reference from this website.

        double rad = 64.10;
        rad *= Math.PI / 180;

        double angDist = 0.343 / 6371;

        Console.WriteLine("Angular distance:" + angDist);

        double latitude =   3.170620;
        double longitude = 103.151279;

        latitude *= Math.PI / 180;
        longitude *= Math.PI / 180;

        double lat2 = Math.Asin(Math.Sin(latitude)*Math.Cos(angDist)+Math.Cos(latitude)*Math.Sin(angDist)*Math.Cos(rad));

        double forAtana = Math.Sin(rad) * Math.Sin(angDist) * Math.Cos(latitude);
        double forAtanb = Math.Cos(angDist)-Math.Sin(latitude)*Math.Sin(lat2);

        double lon2 = longitude + Math.Atan2(forAtana,forAtanb);


        //double finalLat = latitude + lat2;
        //double finalLon = longitude + lon2;

        lat2 *=  180 / Math.PI;
        lon2 *=  180 / Math.PI;

        Console.WriteLine("Target latitude :" + lat2);

        Console.WriteLine("Target longitude : " + lon2);



        Console.ReadKey();
  • Please let me know more about rad = 64.10; and angDist = 0.343 . How you got these two points? – Manish Jain Apr 29 '19 at 10:17
  • @ManishJain the rad value from my code is my location bearing to the target location. Meanwhile the value for angDist are from formula angular distance = d/R, d is the distance that i specify to the target location and R is constant value of Earth radius. You can check this website , where i get the reference for calculation above. I hope it will help. – Mohamad Fathin Apr 30 '19 at 3:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.