I've reached a point where really don't understand why my location data won't be updated although the new horizontalAccuracy is better.
I've sticked mostly to varchar's and rhuettl's code for updating the location data, but for whatever reason it isn't working for me.
Here is the code that bugs me:
Code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(@"Updating location");
NSDate *newLocationEventDate = newLocation.timestamp;
if (signbit(newLocation.horizontalAccuracy)) {
//errorCode
}
else{
timesFired++;
//filter cached and too old locations
//1.Version:
NSLog(@"My Accuracy: %u", myLocation.horizontalAccuracy);
NSLog(@"New Accuracy: %u", newLocation.horizontalAccuracy);
if((!myLocation || myLocation.horizontalAccuracy >= newLocation.horizontalAccuracy) && abs(newLocation.timestamp.timeIntervalSinceNow) > 10) {
//release the cached location, if available
if(myLocation){
[myLocation release];
}
myLocation =[newLocation retain];
}
if (myLocation.horizontalAccuracy < 50 || timesFired >= 3)
{
//stops updating because position is good enough, but only if updateType is set to "Manual"
if(1 == [[[NSUserDefaults standardUserDefaults] stringForKey:@"updateType"] intValue]){
isUpdating = NO;
[myLocationManager stopUpdatingLocation];
}
[self updatedGPS:myLocation];
timesFired = 0;
[mySpinner stopAnimating];
return;
}
}
I've marked the 2 if-clauses where the error occurs red.
So plugged my IPhone to my Mac Mini to test my application. After my initial update I had the following values:
myLocation.horizontalAccuracy = 2604785438;
newLocation.horizontalAccuracy = 0;
The first if-clause only was entered on the first update (because of "!myLocation"). After that this if-clause won't be entered and I always thought "2604785438 >= 0" is TRUE, maybe I shouldn't have skipped Math in school
Therefore I had to change the first is-clause, so that only the time interval was checked no matter how good the horizontalAccuracy was.
That brings me to the 2nd if-clause, so I had the value
myLocation.horizontalAccuracy = 0;
but this if-clause wasn't entered neither, unless "timesFired" was incremented to 3.
I really don't know why this isn't working. I need this application for my thesis so your help would really be appreciated.
I could post my hole code here or I can send you my app, whatever you would need, so that this fu@!ing problem could be solved.