iPhone 开发 - 定位精度
我使用以下条件来确保我获得的位置具有足够的准确性,在我的例子中为 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 时,在实际获得准确结果之前,我得到的结果不准确。您使用什么方法来获取准确/精确的位置信息?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
我得到不准确结果的主要原因是由于以下情况:
if(newLocation.horizontalAccuracy
我使用
kCLLocationAccuracyBest
作为desiredAccuracy,它是一个负数。你不应该用它来进行比较。解决方案:
if(newLocation.horizontalAccuracy <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)