网志中国数据载入中...
 

网志中国数据载入中...

 
 
根据经纬度求地球表面两点间距离
[ 2008-7-3 13:16:00 | By: 不才 ]
 

//language::javascript

//根据经纬度求两点之间的距离

function distanceByLnglat(lng1,lat1,lng2,lat2)
{
    var radLat1 = Rad(lat1);
    var radLat2 = Rad(lat2);
    var a = radLat1 - radLat2;
    var b = Rad(lng1) - Rad(lng2);
    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 * 6378137.0;// 取WGS84标准参考椭球中的地球长半径(单位:m)
    s = Math.round(s * 10000) / 10000;
    return s;
}

function Rad(d)
{
    return d * Math.PI / 180.0;
}

//从google maps的脚本里扒了段代码,没准啥时会用上。
//language:Java


private const double EARTH_RADIUS = 6378.137;
private static double rad(double d)
{
   return d * Math.PI / 180.0;
}

public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
   double radLat1 = rad(lat1);
   double radLat2 = rad(lat2);
   double a = radLat1 - radLat2;
   double b = rad(lng1) - rad(lng2);
   double 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 * EARTH_RADIUS;
   s = Math.Round(s * 10000) / 10000;
   return s;
}

//不过现在就在用,找的方便,发上来给希望大家也能用上,呵呵

 
 
  • 标签:地图求距 
  • 群组:论事非 java天与地 
  • 发表评论:
    网志中国数据载入中...
     
    网志中国数据载入中...

    时 间 记 忆

    网志中国数据载入中...
     

    最 新 日 志

    网志中国数据载入中...
     

    最 新 评 论

    网志中国数据载入中...
     

    搜 索

     

    用 户 登 录

    网志中国数据载入中...
     

    最 新 留 言

    网志中国数据载入中...
     

    友 情 连 接

     
    网志中国数据载入中...