How can i determine if location information returned by CLLocationManager is valid?

末鹿安然 提交于 2019-12-11 13:16:55

问题


How can I determine if location information returned by CLLocationManager is valid?


回答1:


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.




回答2:


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.




回答3:


Also, if the horizontal accuracy is negative, then the latitude and longitude are invalid.



来源:https://stackoverflow.com/questions/465494/how-can-i-determine-if-location-information-returned-by-cllocationmanager-is-val

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!