开发者

iPhone GPS distance between two points

开发者 https://www.devze.com 2023-01-16 06:43 出处:网络
How to find the dis开发者_JAVA技巧tance between from current location to another?CLLocation *location = [[CLLocation alloc] initWithLatitude:doubleLattitude longitude:doubleLongitude];

How to find the dis开发者_JAVA技巧tance between from current location to another?


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.

In the above example user_Location is also a CLLocation object.


There is a method to find the distance between two CLLocations.

CLLocationDistance distance = [firstLocation getDistanceFrom:secondLocation];


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

精彩评论

暂无评论...
验证码 换一张
取 消