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];
精彩评论