当前位置:首页 > ios根据gps坐标来计算两点间的距离

ios根据gps坐标来计算两点间的距离

点击次数:4126  更新日期:2013-09-13

//ios根据gps坐标来计算两点间的距离

//x1,y1 点1的坐标 x2,y2点2的坐标

-(double) gps2m:(double)x1 _y1:(double)y1 _x2:(double)x2 _y2:(double)y2{

   double radLat1 = (x1 * 3.1416 / 180.0);

   double radLat2 = (x2 * 3.1416 / 180.0);

   double a = radLat1 - radLat2;

   double b = (y1 - y2) * 3.1416 / 180.0;

   double s = 2 * asin(sqrt(pow(sin(a / 2), 2)

                                      + cos(radLat1) * cos(radLat2)

                                      * pow(sin(b / 2), 2)));

   s = s * 6378137.0;

   s = round(s * 10000) / 10000;

   return s;

}