美文网首页
iOS 经纬度转直线距离

iOS 经纬度转直线距离

作者: 在这蓝色天空下 | 来源:发表于2016-01-08 11:04 被阅读234次

//将角度转为弧度

+ (float)radians:(float)degrees{

return (degrees*3.14159265)/180.0;

}

//根据经纬度换算出直线距离

+ (float)getDistance:(float)lat1 lng1:(float)lng1 lat2:(float)lat2 lng2:(float)lng2

{         

//地球半径

int R = 6378137;

//将角度转为弧度

float radLat1 = [self radians:lat1];

float radLat2 = [self radians:lat2];

float radLng1 = [self radians:lng1];

float radLng2 = [self radians:lng2];

//结果

float s = acos(cos(radLat1)*cos(radLat2)*cos(radLng1-radLng2)+sin(radLat1)*sin(radLat2))*R;

//精度

s = round(s* 10000)/10000;

return  round(s);

}

相关文章

网友评论

      本文标题:iOS 经纬度转直线距离

      本文链接:https://www.haomeiwen.com/subject/ydbrhttx.html