iPhone 开发 - 定位精度

发布于 2024-08-29 06:33:30 字数 998 浏览 2 评论 0 原文

我使用以下条件来确保我获得的位置具有足够的准确性,在我的例子中为 kCLLocationAccuracyBest。但问题是我的位置仍然不准确。

// Filter out nil locations
if(!newLocation)
    return;

// Make sure that the location returned has the desired accuracy
if(newLocation.horizontalAccuracy < manager.desiredAccuracy)
    return;

// Filter out points that are out of order    
if([newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp] < 0)
    return;

// Filter out points created before the manager was initialized
NSTimeInterval secondsSinceManagerStarted = [newLocation.timestamp timeIntervalSinceDate:locationManagerStartDate];
if(secondsSinceManagerStarted < 0)
    return;

// Also, make sure that the cached location was not returned by the CLLocationManager (it's current) - Check for 5 seconds difference
if([newLocation.timestamp timeIntervalSinceReferenceDate] < [[NSDate date] timeIntervalSinceReferenceDate] - 5)
    return;

当我激活 GPS 时,在实际获得准确结果之前,我得到的结果不准确。您使用什么方法来获取准确/精确的位置信息?

I'm using following conditions in-order to make sure that the location i get has adequate accuracy, In my case kCLLocationAccuracyBest. But the problem is that i still get inaccurate location.

// Filter out nil locations
if(!newLocation)
    return;

// Make sure that the location returned has the desired accuracy
if(newLocation.horizontalAccuracy < manager.desiredAccuracy)
    return;

// Filter out points that are out of order    
if([newLocation.timestamp timeIntervalSinceDate:oldLocation.timestamp] < 0)
    return;

// Filter out points created before the manager was initialized
NSTimeInterval secondsSinceManagerStarted = [newLocation.timestamp timeIntervalSinceDate:locationManagerStartDate];
if(secondsSinceManagerStarted < 0)
    return;

// Also, make sure that the cached location was not returned by the CLLocationManager (it's current) - Check for 5 seconds difference
if([newLocation.timestamp timeIntervalSinceReferenceDate] < [[NSDate date] timeIntervalSinceReferenceDate] - 5)
    return;

When i activate the GPS, i get inaccurate results before i actually get an accurate result. What methods do you use to get accurate/precise location information?

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

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

发布评论

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

评论(2

纵性 2024-09-05 06:33:30

GPS 速度很慢,至少与用户耐心相比是这样,因此位置管理器会返回最好的数据,直到获得新的有效 GPS 读数。你可以让用户等待多长时间才能获得准确的读数,或者像谷歌地图那样获得某种增量反馈,用一个圆圈而不是一个点。

GPS is slow, at least compared to user patience, so the location manager returns the best it has until it gets a new, valid GPS read. You can either make the user wait however long it takes to get an accurate read, or have some kind of incremental feedback the way google maps does, with a circle than a dot.

梦屿孤独相伴 2024-09-05 06:33:30

我得到不准确结果的主要原因是由于以下情况:

if(newLocation.horizo​​ntalAccuracy

我使用 kCLLocationAccuracyBest 作为desiredAccuracy,它是一个负数。你不应该用它来进行比较。

解决方案:
if(newLocation.horizo​​ntalAccuracy <10.0)

The main reason i was getting inaccurate results was because of this condition:

if(newLocation.horizontalAccuracy < manager.desiredAccuracy)

I was using kCLLocationAccuracyBest as desiredAccuracy and it's a negative number. You shouldn't use it for comparison.

Solution:
if(newLocation.horizontalAccuracy < 10.0)

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