如何找到从当前位置到另一个位置之间的距离?
答案 0 :(得分:6)
CLLocation *location = [[CLLocation alloc] initWithLatitude:doubleLattitude longitude:doubleLongitude];
double distanceDouble;
if([user_Location respondsToSelector:@selector(distanceFromLocation:)])
distanceDouble = [user_Location distanceFromLocation:location];
else
distanceDouble = [user_Location getDistanceFrom:location];
这样你就支持OS 4.0和3.0,因为getDistanceFrom现在是deprecated。
在上面的示例中,user_Location也是一个CLLocation对象。
答案 1 :(得分:0)
有一种方法可以找到两个CLLocations之间的距离。
CLLocationDistance distance = [firstLocation getDistanceFrom:secondLocation];
答案 2 :(得分:0)
CLLocation *locA = [[CLLocation alloc] initWithLatitude:"current location latitude" longitude:"current location longitude";
CLLocation *locB = [[CLLocation alloc] initWithLatitude:"other latitude" longitude:"other longitude";
CLLocationDistance distance = [locA distanceFromLocation:locB];