Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-07-2009, 10:41 AM   #28 (permalink)
zword
Registered Member
 
Join Date: Nov 2008
Posts: 34
zword is on a distinguished road
Default Checking for horizontalAccuracy doesn't work

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.
zword is offline   Reply With Quote
 

» Advertisements
» Online Users: 447
14 members and 433 guests
apatsufas, aqlucky, bardariz01, DavisWenins, guillermotricia, iLearnColors, iOS.Lover, IphoneSdk, jeroenkeij, LunarMoon, MAMN84, nicsmotherman, QuantumDoja, Viekiehug
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,612
Threads: 94,086
Posts: 402,792
Top Poster: BrianSlick (7,990)
Welcome to our newest member, DavisWenins
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.