开发者

DistanceFromLocation Error

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜