代码如下:
#include <math.h>
#include <stdio.h>
struct pos
{
double la ; //维度
double lo ; //经度
};
//( 113.58762378623 , 37.86236 ) - ( 113.58762378623 , 38 )
//d = R * arccos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1 - lon2))
int main(int argc,char**argv)
{
#define R (6371008.7714)
#define pi (3.1415926)
struct pos x1,y1 ;
x1.lo = 113.58762378623 ,x1.la = 37.86236 ;
y1.lo = 113.58762378623 ,y1.la = 38 ;
double distance = R *acos(sin(x1.la)*sin(y1.la) + cos(x1.la)*cos(y1.la)*cos(x1.lo-y1.lo) ) ;
distance = distance * pi / 180 ;
printf("distance:%lf \r\n",distance) ;
return 0 ;
}
输出结果:
distance:15304.890514