views:

276

answers:

5

hi all, i want to use the best Coordinate. but one thing is confusing me

here i want to check that if new location accuracy is better then use new location otherwise use old location

if (newLocation.horizontalAccuracy>oldLocation.horizontalAccuracy)
{
    self.bestEffortAtLocation=newLocation; // this mean new location is better accurate
}
else
{
    self.bestEffortAtLocation=oldLocation; // this mean old location is better accurate
}

i want to know that above check is correct or not?

i know this is a stupid question. but now at this time i am at surface level.

Please suggest

A: 

     horizontalAccuracy is the radius of uncertainty for the location, that is the more its value the less accurate your location is. So you should revert the comparison you use.
    I'd also suggest to introduce some threshold below which any new location is good.

Vladimir
A: 

CLLocation.horizontalAccuracy is defined as

horizontalAccuracy

The radius of uncertainty for the location, measured in meters. (read-only)

@property(readonly, NS_NONATOMIC_IPHONEONLY) CLLocationAccuracy horizontalAccuracy

Discussion

The coordinate’s latitude and longitude identify the center of the circle and this value indicates the radius of that circle. A negative value indicates that the coordinate’s latitude and longitude are invalid.

So by that definition, the "better" accuracy is the lower value of the two that is non-negative.

slf
+6  A: 

That's not really a good idea. To see why, let's say we call the accuracy at time t A(t), and it will be given in units of meters. We'll imagine the following situation:

  • A(0) = m meters
  • A(t) = n > m meters
  • v(0) = k meters/sec, where k/t > m
  • zero acceleration on the interval [0, t]

That is:

  • At time zero, your accuracy is some value m meters.
  • At some later time t, your accuracy is a worse value n meters.
  • Your speed at time zero will carry you outside the boundaries of the radius of m after time t.
  • You have constant acceleration, so your velocity doesn't change.

Using your algorithm, you would decline to use the new GPS location when you're at time t because n is worse than m, even though the user couldn't possibly anywhere near the old location. Their speed has carried them past the radius of m. That's clearly not right.

Instead, here's a rudimentary algorithm to decide whether the new location is better or worse than the old one:

  • At periodic intervals of t seconds each, store a 3-tuple (L, v, A) containing the location L, velocity v, and accuracy A of the user.

  • At some time u you would like to know what the best guess for the user's location is.

  • Examine the location at time u - t. If Aold > Anew (remember, higher values of accuracy are worse if they're measured in meters), then use the new location since it's more accurate.

  • If Aold < Anew, things are a little different. If A/t exceeds 2v, the user is probably still inside the accuracy circle, so use the old L. But if not, then the user has traveled outside the bounds of the accuracy circle, so use the new L.

John Feminella
That was my exact same idea when I read the question.
Peter
"If A/t exceeds 2v/t" - dimensional analysis alone shows that must be wrong. The first is a speed, the second an acceleration.
MSalters
Whoops, typo. Fixed!
John Feminella
A: 

Just because the accuracy has gone down, does that really mean you want to ignore the reading? For example, say I'm driving my car and I go behind a few tall buildings through a busy city centre, if you're still comparing the HDOP as it's known then you're going to leave a marker right outside the city, until I get to the other end where the signal is the same or stronger than the original.

In fact, once you've found the very best position (in a nice open field not moving lets say), then the HDOP is going to increase and you'll never update from your old location...

Ian
A: 

No. The easiest fix is to increment the old accuracy A(0) by the likely travelled distance, v*t. Then check whether A(0) + v*t) < A(t) - if so, use the old position instead of the new.

MSalters
What about a situation in which the accuracy A(t) steadily worsens such that A(0) + v*t is always less? Using the old position doesn't seem right if the new position is well outside of its original spot.
John Feminella
Do the math: if the new position is 100 meters away from the original spot, but the accuracy has decreased from <10 meters to <200 meters, then stick with the original measurement. In practice, the accuracy worsens only for so long before the GPS sensor loses the signal entirely.
MSalters