开发者

iPhone GPS distance between two points

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜