美文网首页
计算两地距离多少公里或者英里

计算两地距离多少公里或者英里

作者: BabyNeedCare | 来源:发表于2018-11-12 09:08 被阅读0次

    CLLocation *lastLocation = [[CLLocation alloc] initWithLatitude:coords.latitude longitude:coords.longitude];
    CLLocation *nowLocation = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];

    int distanceMeters = [lastLocation distanceFromLocation:nowLocation];
             
                if(appDelegate.isKMOrMILE == 0)
                {
                    [cardistanceLabel setText:[NSString stringWithFormat:@"%d KM",distanceMeters/1000]];//公里
                }
                else if(appDelegate.isKMOrMILE == 1)
                {
                    int data = (distanceMeters/1000)/1.6093;
                    [cardistanceLabel setText:[NSString stringWithFormat:@"%d MILE",data]];//英里
                }

    相关文章

      网友评论

          本文标题:计算两地距离多少公里或者英里

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