views:

808

answers:

3

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

+1  A: 

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.

Tom Harrington
+1  A: 

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.

rustyshelf
A: 

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