开发者

DistanceFromLocation Error

开发者 https://www.devze.com 2023-04-03 05:59 出处:网络
CLLocation *useOne = [[CLLocation alloc] initWithLatitude:40.074744 lon开发者_StackOverflow社区gitude:116.240179];
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);
0

精彩评论

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