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

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]]; //英里
                 }



你可能感兴趣的:(计算两地距离多少公里或者英里)