//将角度转为弧度
+ (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);
}