iPhone GPS两点之间的距离

时间:2010-09-14 14:21:15

标签: iphone

如何找到从当前位置到另一个位置之间的距离?

3 个答案:

答案 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];