为什么CLLocation坐标在显示时会失去精度?

bil*_*aya 0 iphone precision gps ios-simulator

我正在进行一些实验,试图通过对随时间收集的数据进行加权平均来提高iPhone上的GPS准确度.我注意到控制台,iPhone模拟器和iPhone本身的坐标显示有所不同.

我正在运行基本的CoreLocation代码来设置我的位置管理器.

self.locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

[locationManager startUpdatingLocation];
Run Code Online (Sandbox Code Playgroud)

在我的locationManager中:didUpdateToLocation:fromLocation:方法我使用NSLog以几种格式将坐标写入控制台,然后在我的IBOutlets中显示它们.

NSLog(@"%@", newLocation);
NSLog(@"%f", newLocation.coordinate.latitude);
NSLog(@"%e", newLocation.coordinate.latitude);
NSLog(@"%E", newLocation.coordinate.latitude);

self.latitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];
self.longitude.text = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];
self.altitude.text = [NSString stringWithFormat:@"%f", newLocation.altitude];
self.horizontalAccuracy.text = [NSString stringWithFormat:@"%f", newLocation.horizontalAccuracy];
self.verticalAccuracy.text = [NSString stringWithFormat:@"%f", newLocation.verticalAccuracy];
Run Code Online (Sandbox Code Playgroud)

写入控制台的值如下所示.

NSLog(@"%@", ...);  | <+42.40334972, -71.27483790> +/- 240.00m (speed -1.00 mps / course -1.00) @ 2010-10-19 12:15:00 GMT
NSLog(@"%f", ...); | 42.403350
NSLog(@"%e", ...); | 4.240335e+01
NSLog(@"%E", ...); | 4.240335E+01
Run Code Online (Sandbox Code Playgroud)

屏幕上显示的纬度和经度如下.

Latitude | 42.403350
Longitude | -7.274838
Run Code Online (Sandbox Code Playgroud)

由于纬度和经度是CLLocationDegrees,即双倍,我使用%f将坐标写入控制台并在屏幕上显示,我不认为"原始"坐标将从8到6舍入地方.(我也不知道iPhone上的GPS接收器是否以与MacBook Pro相同的精度收集坐标.)

显然,我可以将CLLocation对象存储在一个数组中,并在我的加权平均计算中使用更精确的坐标,但我还想在屏幕上显示增加的精度.任何变通办法或想法?

提前致谢.

Vla*_*mir 7

6位数只是使用NSLog(和printf函数)浮点输出的默认值,并且存储在newLocation变量中的坐标值不会失去其精度,您可以显式设置需要打印的位数:

NSLog(@"%.8f", ...);// will print 8 decimal digits
Run Code Online (Sandbox Code Playgroud)