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

前端 未结 5 1550
自闭症患者
自闭症患者 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:55

    This code works for me :
    1. We have to count the distance ( speed * time ).
    2. The code converts the distance to KM because earthradius is used in KM too.

                const double radiusEarthKilometres = 6371.01f;
    
                kmDistance = kmSpeed * (timer1.Interval / 1000f) / 3600f;
    
                var distRatio = kmDistance / radiusEarthKilometres;
                var distRatioSine = Math.Sin(distRatio);
                var distRatioCosine = Math.Cos(distRatio);
    
                var startLatRad = deg2rad(lat0);
                var startLonRad = deg2rad(lon0);
    
                var startLatCos = Math.Cos(startLatRad);
                var startLatSin = Math.Sin(startLatRad);
    
                var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(angleRadHeading)));
    
                var endLonRads = startLonRad
                    + Math.Atan2(Math.Sin(angleRadHeading) * distRatioSine * startLatCos,
                        distRatioCosine - startLatSin * Math.Sin(endLatRads));
    
                newLat = rad2deg(endLatRads);
                newLong = rad2deg(endLonRads);
    

提交回复
热议问题