如何获得指定精度的一次性位置?

发布于 2024-09-14 06:23:24 字数 544 浏览 2 评论 0原文

在文档中,它说它获得了一个大概的位置,然后以越来越精细的精度不断更新。我有一个按钮

[locManager startUpdatingLocation];

,然后我实施

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    [locManager stopUpdatingLocation];
}

并让它在某个地方得到指示。由于某种原因,当我开车去某个地方时,它不会更新位置。我认为这是因为它获得了“大致位置”,然后没有足够的时间来获得准确的读数。我也有

locManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

什么想法吗?只需要一次准确的读数。难住了。谢谢。

In the documentation it says that it gets an approximate location and then keeps updating with finer and finer precision. I have a button that does

[locManager startUpdatingLocation];

and then I implement

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
    [locManager stopUpdatingLocation];
}

and have it get directions somwhere. For some reason it's not updating locations when I drive somewhere. I would assume this is because it gets the "general location", and then doesn't have enough time to get an accurate reading. I also have

locManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;

Any thoughts? just need one time accurate readings. stumped. thanks.

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

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

发布评论

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

评论(1

-小熊_ 2024-09-21 06:23:24

快速破解解决方案:

if (newLocation.horizontalAccuracy > 2*locManager.desiredAccuracy) {
  return;
}

更好的解决方案可能是等到准确性停止提高(根据最近 5 次更新的平均值)。

Quick hack solution:

if (newLocation.horizontalAccuracy > 2*locManager.desiredAccuracy) {
  return;
}

A better solution might be to wait until accuracy stops improving, averaged over the last 5 updates or so.

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