how to use direction angle and speed to calculate next time's latitude and longitude

前端 未结 5 1628
自闭症患者
自闭症患者 2021-02-04 07:42

I have know my current position({lat:x,lon:y}) and I know my speed and direction angle; How to predict next position at next time?

5条回答
  •  耶瑟儿~
    2021-02-04 07:58

    Here in JS for calculating lat and lng given bearing and distance:

    //lat, lng in degrees. Bearing in degrees. Distance in Km
    calculateNewPostionFromBearingDistance = function(lat, lng, bearing, distance) {
      var R = 6371; // Earth Radius in Km
    
      var lat2 = Math.asin(Math.sin(Math.PI / 180 * lat) * Math.cos(distance / R) + Math.cos(Math.PI / 180 * lat) * Math.sin(distance / R) * Math.cos(Math.PI / 180 * bearing));
      var lon2 = Math.PI / 180 * lng + Math.atan2(Math.sin( Math.PI / 180 * bearing) * Math.sin(distance / R) * Math.cos( Math.PI / 180 * lat ), Math.cos(distance / R) - Math.sin( Math.PI / 180 * lat) * Math.sin(lat2));
    
      return [180 / Math.PI * lat2 , 180 / Math.PI * lon2];
    };
    
    calculateNewPostionFromBearingDistance(60,25,30,1)
    [60.007788047871614, 25.008995333937197]
    

提交回复
热议问题