首页 > 其他 > 详细

根据经纬度,方位角,距离,计算新的经纬度

时间:2021-05-21 12:04:36      阅读:48      评论:0      收藏:0      [点我收藏+]

直接上代码

function destination(lng,lat, heading, distance) {
                //计算扇形的眯点坐标
                heading = (heading + 360) % 360;
                var rad = Math.PI / 180,
                    radInv = 180 / Math.PI,
                    R = 6378137, // approximation of Earth‘s radius
                    lon1 = lng * rad,
                    lat1 = lat * rad,
                    rheading = heading * rad,
                    sinLat1 = Math.sin(lat1),
                    cosLat1 = Math.cos(lat1),
                    cosDistR = Math.cos(distance / R),
                    sinDistR = Math.sin(distance / R),
                    lat2 = Math.asin(
                        sinLat1 * cosDistR + cosLat1 * sinDistR * Math.cos(rheading)
                    ),
                    lon2 =
                        lon1 +
                        Math.atan2(
                            Math.sin(rheading) * sinDistR * cosLat1,
                            cosDistR - sinLat1 * Math.sin(lat2)
                        );
                lon2 = lon2 * radInv;
                lon2 = lon2 > 180 ? lon2 - 360 : lon2 < -180 ? lon2 + 360 : lon2;
                lat2 = lat2 * radInv
                return [lon2,lat2]
            }

封装好的方法,之后调用方法即可
var new = destination(lng,lat, heading, distance)//经度,纬度,方位角,距离
console.log(new)
 

 

根据经纬度,方位角,距离,计算新的经纬度

原文:https://www.cnblogs.com/wuzhaoyu/p/14792493.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!