SQL Server 计算经纬度直线距离

declare @Lng decimal(18,6)=114.059920--经度
declare @Lat decimal(18,6)=22.544884--纬度

declare @GPSLng decimal(18,6)=114.056300--经度
declare @GPSLat decimal(18,6)=22.521447--纬度


select 6378.137*ACOS(SIN(@GPSLat/180*PI())*SIN(@Lat/180*PI())+COS(@GPSLat/180*PI())*COS(@Lat/180*PI())*COS((@GPSLng-@Lng)/180*PI()))
结果:2.63541089201227
6378.137  地球半径(单位:公里)

 

JS实现:

function GetDistance( lat1,  lng1,  lat2,  lng2){
    var radLat1 = lat1*Math.PI / 180.0;
    var radLat2 = lat2*Math.PI / 180.0;
    var a = radLat1 - radLat2;
    var  b = lng1*Math.PI / 180.0 - lng2*Math.PI / 180.0;
    var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
    Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
    s = s *6378.137 ;// EARTH_RADIUS;
    s = Math.round(s * 10000) / 10000;
    return s;
}

GetDistance(22.544884,114.059920,22.521447,114.056300)=2.6354
posted on 2022-04-15 23:23  wakaka_wka  阅读(254)  评论(0编辑  收藏  举报