Calculate bearing between two locations (lat, long)

后端 未结 7 1671
不知归路
不知归路 2020-12-13 20:35

I\'m trying to develop my own augmented reality engine.

Searching on internet, I\'ve found this useful tutorial. Reading it I see that the important thing is bearing

7条回答
  •  猫巷女王i
    2020-12-13 20:42

    /* Kirit vaghela answer has been modified.. Math.sin gives the radian value so to get degree value we need to pass Math.toRadians(value) inside Math.sin() or Math.cos() */

        double lat1 = 39.099912;
        double lat2 = 38.627089;
        double lng1 = -94.581213;
        double lng2 = -90.200203;
    
        double dLon = (lng2-lng1);
        double x = Math.sin(Math.toRadians(dLon)) * Math.cos(Math.toRadians(lat2));
        double y = Math.cos(Math.toRadians(lat1))*Math.sin(Math.toRadians(lat2)) - Math.sin(Math.toRadians(lat1))*Math.cos(Math.toRadians(lat2))*Math.cos(Math.toRadians(dLon));
        double bearing = Math.toDegrees((Math.atan2(x, y)));
        System.out.println("BearingAngle : "+bearing);
    

提交回复
热议问题