两个位置之间 距离的计算

//距离计算

- (NSString *)distanceLatitude:(NSString*)latitude longitude:(NSString*)longitude

{

//距离计算

CLLocation *orig            =[[CLLocation alloc] initWithLatitude:[self.userLocation doubleValue]  longitude:[self.userlongitude doubleValue]];

CLLocation* dist            =[[CLLocation alloc] initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue] ];

CLLocationDistance kilometers=[orig distanceFromLocation:dist];

float distanceF            = kilometers;

NSString *distanceSTr      = [NSString stringWithFormat:@"%0.fM",distanceF];

if(distanceF > 1000)

{

distanceF              = kilometers/1000;

distanceSTr            = [NSString stringWithFormat:@"%0.fkm",distanceF];

}

return distanceSTr;

}

你可能感兴趣的:(两个位置之间 距离的计算)