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

发布于 2024-10-01 12:32:26 字数 1738 浏览 1 评论 0原文

我正在做一些实验,尝试通过对一段时间内收集的数据进行加权平均来提高 iPhone 上的 GPS 精度。我注意到控制台、iPhone 模拟器和 iPhone 本身的坐标显示存在差异。

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

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

[locationManager startUpdatingLocation];

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

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];

写入控制台的值如下。

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

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

Latitude | 42.403350
Longitude | -7.274838

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

显然,我可以将 CLLocation 对象存储在数组中,并在加权平均计算中使用更精确的坐标,但是我还想在屏幕上显示增加的精度。有什么解决方法或想法吗?

提前致谢。

I'm working on some experiments to try and increase the GPS accuracy on an iPhone by performing weighted averages on data collected over time. I've noticed a difference in the display of coordinates in the console, on the iPhone simulator, and on the iPhone itself.

I'm running basic CoreLocation code to set up my Location Manager.

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

[locationManager startUpdatingLocation];

In my locationManager: didUpdateToLocation: fromLocation: method I write the coordinates to the console in several formats using NSLog before displaying them in my 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];

The values that are written to the console are as follows.

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

The latitude and longitude displayed onscreen are as follows.

Latitude | 42.403350
Longitude | -7.274838

Since the latitude and longitude are CLLocationDegrees, i.e. doubles, and I'm using the %f to write the coordinates to the console and display them onscreen, I didn't think the "raw" coordinates would be rounded up from 8 to 6 decimal places. (I also don't know if the GPS receiver on the iPhone collects coordinates at the same level of precision as the MacBook Pro.)

Obviously I can store the CLLocation objects in an array and use the more precise coordinates in my weighted average calculations but I also wanted to display the increased precision onscreen. Any workarounds or thoughts?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2024-10-08 12:32:26

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

NSLog(@"%.8f", ...);// will print 8 decimal digits

6 digits is just a default value for floating point output using NSLog (and printf function) and the coordinate values stored in newLocation variable do not loose their precision, you can explicitly set the number of digits you need to print:

NSLog(@"%.8f", ...);// will print 8 decimal digits
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文