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
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:
That is:
mmeters.t, your accuracy is a worse valuenmeters.mafter timet.Using your algorithm, you would decline to use the new GPS location when you’re at time
tbecausenis worse thanm, even though the user couldn’t possibly anywhere near the old location. Their speed has carried them past the radius ofm. 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
tseconds each, store a 3-tuple(L, v, A)containing the location L, velocity v, and accuracy A of the user.At some time
uyou 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/texceeds2v, the user is probably still inside the accuracy circle, so use the oldL. But if not, then the user has traveled outside the bounds of the accuracy circle, so use the newL.