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); 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值