DistanceFromLocation错误

Ale*_*xQu 0 ios

CLLocation *useOne = [[CLLocation alloc] initWithLatitude:40.074744 longitude:116.240179];

CLLocation *useTwo = [[CLLocation alloc] initWithLatitude:40.079106 longitude:116.243469];

CLLocationDistance distance = [useOne distanceFromLocation:useTwo];
NSLog(@"%d",distance);
Run Code Online (Sandbox Code Playgroud)

但我得到的结果是"距离= 1921570242"米.绝对这个结果是不正确的.

那我在哪里错了?

Vla*_*mir 6

你的计算是正确的,但你打印的方式是错误的.CLLocationDistance是一个double,所以格式说明符NSLog应该是%f(%d用于整数):

NSLog(@"%f",distance);
Run Code Online (Sandbox Code Playgroud)