Reputation: 1889
My code should accept locations that has accuracy under 100, if the new location accuracy is smaller then the old more in 20 then use the new one. Also if the distance from the new location to the old one is larger then 200 use it.
I have no idea why but after testing my code I got the following locations in my db:
The last 3 records are less then 200m from each other, how come I use them?? Here is the code:
int Aloc = (int) loc.getAccuracy();
int AnewLoc = (int) newLoc.getAccuracy();
if(Aloc > AnewLoc +20)
sendTask();
else
{
float distance = loc.distanceTo(newLoc);
if(distance > 200)
sendTask();
}
This code is executed to locations that their accuracy is less then 100.
EDIT after changing the condition to
if((AnewLoc+20) < Aloc)
I received the following records:
The new records has larger accuracy then the old one and his distance is less then 200(0.01407 km which is 14 meters). I can't understand how come it pass by the code and sent to the db.
Upvotes: 1
Views: 2066
Reputation: 7016
Change your checking logic like this
int Aloc = (int) loc.getAccuracy();
int AnewLoc = (int) newLoc.getAccuracy();
if(AnewLoc < ( Aloc+20))
sendTask();
else
{
float distance = loc.distanceTo(newLoc);
if(distance > 200)
sendTask();
}
This should work
Upvotes: 1