两点经纬度计算距离

#include "math.h"
#include "assert.h"

namespace {
    #define _TRUE   1
    #define _FALSE  0
    static const int Earth_Radius = 6378137;	//地球半径
    static const double e = 0.081813369f;

    double radian(double d)
    {
        return d*M_PI/180.0;//角度1°=M_PI/180
    }
}

double LL_dst::Get_distance(double lat1,double lng1,double lat2,double lng2)
{
    double radLat1=radian(lat1);
    double radLat2=radian(lat2);
    double a=radLat1-radLat2;
    double b=radian(lng1)-radian(lng2);
    double dst=2*asin((sqrt(pow(sin(a/2),2)+cos(radLat1)*cos(radLat2)*pow(sin(b/2),2))));
    dst=dst*Earth_Radius;
    //	dst=round(dst*10000)/10000;
    return dst;
}

你可能感兴趣的:(c/c++,算法)