如何确定 CLLocationManager 返回的位置信息是否有效?
如何确定 CLLocationManager 返回的位置信息是否有效?
How can I determine if location information returned by CLLocationManager is valid?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能绝对确定。 你会得到手机关于它所在位置的最佳信息,无论你信不信,但你无法轻松验证该位置。
可能对某些人有帮助的一件事是检查您获得的位置的时间戳。 Core Location 会缓存数据,你得到的第一个结果可能是很旧的读数。 如果手机发生了任何移动,则可能会不准确。 另一方面,它可能仍然是正确的,并且在新结果出现之前您确实无法确定。尽管如此,丢弃来自应用程序启动之前的时间戳的核心位置中的任何数据通常很有用 - 它可能是好的数据,但很有可能不是。 稍后的读数将是新的,并且与手机所能提供的一样值得信赖。
You can't be absolutely certain. You'll get the phone's best idea about where it is, and you can believe it or not, but you can't easily verify that location.
One thing that may help some is to check the timestamp the locations you get. Core Location will cache data, and the first result you get may be a very old reading. If the phone has moved at all it may be inaccurate. On the other hand it might still be correct, and you really can't be sure until new results come in. Nevertheless it's often useful to throw away any data from Core Location where the timestamp is from before your app started up-- it might be good data but there's a decent chance that it's not. Later readings will be new and are as trustworthy as the phone can make them.
另外,如果水平精度为负,则纬度和经度无效。
Also, if the horizontal accuracy is negative, then the latitude and longitude are invalid.
需要注意两件事:时间戳和 hdop(水平精度)。 第一个会告诉您读数何时进行,第二个会告诉您读数的错误程度。 例如,hdop 为 1000 将告诉您测量精确度在 1000 米以内。 显然 hdop 越低越好。
它们都在您获得的核心位置更新中。
Two things to look for, the timestamp and the hdop (Horizontal Degree of Precision). The first one will tell you when the reading was taken, the second will tell you the level of error in the reading. For example a hdop of 1000 will tell you that the measurement is accurate to within 1000 metres. Obviously the lower the hdop the better.
They are both in the Core Location update you get.