寻找2点之间距离的新方法

时间:2011-01-24 05:36:56

标签: iphone location distance

我使用以下代码查找2点之间的距离:

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:28.3636 longitude:-77.1212];

CLLocation *location2 = [[CLLocation alloc] initWithLatitude:42.353297 longitude:-71.578858];

float target = [location1 getDistanceFrom:location2];

但现在Apple已弃用getDistanceFrom。

我应该尝试执行相同的任务?

2 个答案:

答案 0 :(得分:6)

-distanceFromLocation:呢?它甚至在-getDistanceFrom:的文档中明确提到作为替代方法。

答案 1 :(得分:2)

您想使用'distanceFromLocation:'。有关详细信息,请参阅文档:http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html