Calculate bearing between 2 points with javascript

前端 未结 2 1307
情书的邮戳
情书的邮戳 2020-12-18 03:54

I want to calculate the bearing from point 1 to point 2 The input format is 52.070564 - 4.407116

No matter what i try i cannot get an correct output.

The for

2条回答
  •  执笔经年
    2020-12-18 04:35

    start_latitude  = 12.9389352
    start_longitude = 77.6994306
    stop_latitude   = 12.939103
    stop_longitude  = 77.705825
    
    var y = Math.sin(stop_longitude-start_longitude) * Math.cos(stop_latitude);
    var x = Math.cos(start_latitude)*Math.sin(stop_latitude) -
            Math.sin(start_latitude)*Math.cos(stop_latitude)*Math.cos(stop_longitude-start_longitude);
    var brng = Math.atan2(y, x) * 180 / Math.PI;
    
    
    alert("Bearing in degreee:  " + brng);

提交回复
热议问题