简体   繁体   English

iPhone GPS两点之间的距离

[英]iPhone GPS distance between two points

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

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

This way you support both OS 4.0 and 3.0 since getDistanceFrom is deprecated now. 由于现在不赞成使用 getDistanceFrom,因此您可以同时支持OS 4.0和3.0。

In the above example user_Location is also a CLLocation object. 在上面的示例中,user_Location也是CLLocation对象。

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

有一种方法可以找到两个CLLocation之间的距离。

CLLocationDistance distance = [firstLocation getDistanceFrom:secondLocation];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM