温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS 2个坐标之间的距离

发布时间:2020-07-19 11:39:38 来源:网络 阅读:441 作者:大头狼小鬼 栏目:移动开发

// 计算两坐标之间的距离

double distanceWithcoord(double lon1,double lat1,double lon2,double lat2)

{

    double er = 6378137;

    double radlat1 = PI*lat1/180.0f;

    double radlat2 = PI*lat2/180.0f;

    double radlong1 = PI*lon1/180.0f;

    double radlong2 = PI*lon2/180.0f;

    if( radlat1 < 0 ) radlat1 = PI/2 + fabs(radlat1);// south

    if( radlat1 > 0 ) radlat1 = PI/2 - fabs(radlat1);// north

    if( radlong1 < 0 ) radlong1 = PI*2 - fabs(radlong1);//west

    if( radlat2 < 0 ) radlat2 = PI/2 + fabs(radlat2);// south

    if( radlat2 > 0 ) radlat2 = PI/2 - fabs(radlat2);// north

    if( radlong2 < 0 ) radlong2 = PI*2 - fabs(radlong2);// west


    double x1 = er * cos(radlong1) * sin(radlat1);

    double y1 = er * sin(radlong1) * sin(radlat1);

    double z1 = er * cos(radlat1);

    double x2 = er * cos(radlong2) * sin(radlat2);

    double y2 = er * sin(radlong2) * sin(radlat2);

    double z2 = er * cos(radlat2);

    double d = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));

    

    double theta = acos((er*er+er*er-d*d)/(2*er*er));

    double dist  = theta*er;

    return dist;

}


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios
AI