CLLocation *useOne = [[CLLocation alloc] initWithLatitude:40.074744 lon开发者_StackOverflow社区gitude:116.240179];
CLLocation *useTwo = [[CLLocation alloc] initWithLatitude:40.079106 longitude:116.243469];
CLLocationDistance distance = [useOne distanceFromLocation:useTwo];
NSLog(@"%d",distance);
But I got the result is "distance=1921570242" metres. absolutely this result was incorrect.
So where am I wrong?
Your calculations are correct, but the way you print is wrong. CLLocationDistance
is a double, so format specifier in NSLog
should be %f
(%d
is used for integers):
NSLog(@"%f",distance);
精彩评论