iOS通过经纬度计算两个坐标之间的距离


方法一:http://www.360doc.com/content/15/0118/18/20918780_441837862.shtml

+(double)distanceBetweenOrderBy:(double)lat1 :(double)lat2 :(double)lng1 :(double)lng2{

    doubledd = M_PI/180;

    doublex1=lat1*dd,x2=lat2*dd;

    doubley1=lng1*dd,y2=lng2*dd;

    doubleR = 6371004;

    doubledistance = (2*R*asin(sqrt(2-2*cos(x1)*cos(x2)*cos(y1-y2) - 2*sin(x1)*sin(x2))/2));

    //km  返回

    //     return  distance*1000;

       

    //返回 m

    return  distance;

   

}


方法二:http://www.open-open.com/code/view/1436347637036

    CLLocation *orig=[[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue]  longitude:[mainDelegate.longitude_self doubleValue]] autorelease];                 CLLocation* dist=[[[CLLocation alloc] initWithLatitude:[tmpNewsModel.latitude doubleValue] longitude:[tmpNewsModel.longitude doubleValue] ] autorelease];                             CLLocationDistance kilometers=[orig distanceFromLocation:dist]/1000; 

    NSLog(@"距离:",kilometers); 


你可能感兴趣的:(iOS通过经纬度计算两个坐标之间的距离)