PDA

View Full Version : CLManager - slow and not accurate




varchar
Sep 1, 2008, 09:08 PM
Hi,

I am successfully using the CLLocationManager (and associated objects) to interact with the GPS. It seems to work "ok", but the main problem I am having is that it does not seem to be updating properly.

For example:

I get GPS coordinates at one location. Then I walk about 1 block down and the coordinates remain the same (yes I am looking after the 3rd decimal point)

Interesting enough, when I use the iphone maps app, it seems to update more frequently and accurately... Any suggestions?

Below is my code (keep in mind I modified most of it from various sources, including the SDK examples).




// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{


NSMutableString *lastTimeUpdated = [[[NSMutableString alloc] init] autorelease];
NSMutableString *currentLatitude = [[[NSMutableString alloc] init] autorelease];
NSMutableString *currentLatitudeDirection = [[[NSMutableString alloc] init] autorelease];

NSMutableString *currentLongitude = [[[NSMutableString alloc] init] autorelease];
NSMutableString *currentLongitudeDirection = [[[NSMutableString alloc] init] autorelease];

// Timestamp
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[lastTimeUpdated appendFormat:@"%@\n\n", [dateFormatter stringFromDate:newLocation.timestamp]];

// Horizontal coordinates
if (signbit(newLocation.horizontalAccuracy))
{
// Negative accuracy means an invalid or unavailable measurement
[currentLatitude appendString:LocStr(@"LatLongUnavailable")];
}
else
{
// CoreLocation returns positive for North & East, negative for South & West

//currentLatitude = [NSString stringWithFormat:@"%lf",fabs(newLocation.coordinate.latitude)];
currentLatitude = [NSString stringWithFormat:@"%lf",newLocation.coordinate.latitude];
currentLatitudeDirection = signbit(newLocation.coordinate.latitude) ? LocStr(@"South") : LocStr(@"North");

currentLongitude = [NSString stringWithFormat:@"%lf",fabs(newLocation.coordinate.longitude)];
currentLongitude = [NSString stringWithFormat:@"%lf",newLocation.coordinate.longitude];

currentLongitudeDirection = signbit(newLocation.coordinate.latitude) ? LocStr(@"West") : LocStr(@"East");


// [update appendString:@"\n"];
//[update appendFormat:LocStr(@"MeterAccuracyFormat"), newLocation.horizontalAccuracy];
}

// Send the update to our delegate
[self.delegate newLocationUpdate: lastTimeUpdated: currentLatitude: currentLatitudeDirection: currentLongitude: currentLongitudeDirection];
}



-(void)newLocationUpdate: (NSString *)lastTimeUpdated: (NSString *) currentLatitude: (NSString *) currentLatitudeDirection: (NSString *) currentLongitude:(NSString *) currentLongitudeDirection {


[activityIndicator startAnimating];

myCurrentLatitude= currentLatitude;
myCurrentLongitude = currentLongitude;


[[MyCLController sharedInstance].locationManager stopUpdatingLocation];


}



gnasher729
Sep 2, 2008, 03:21 AM
You are in violation of the NDA that you agreed to when you downloaded the iPhone SDK.

ploppy
Sep 2, 2008, 04:05 AM
You are in violation of the NDA that you agreed to when you downloaded the iPhone SDK.

So what? So is everybody else on this forum. Nobody, Apple included, seems to care.

[[MyCLController sharedInstance].locationManager stopUpdatingLocation];

Core Location is not updating because you're telling it not to.

varchar
Sep 2, 2008, 11:06 PM
I am stopping the update after I receive and update, and then starting it again...

In either case, even when I take the stopupdating out it still gives a problem...

varchar
Sep 2, 2008, 11:06 PM
You are in violation of the NDA that you agreed to when you downloaded the iPhone SDK.



How so? Please explain... I would like to know... all I am doing is accessing the GPS coordinates.

mspatts
Oct 3, 2008, 12:13 PM
I am stopping the update after I receive and update, and then starting it again...

In either case, even when I take the stopupdating out it still gives a problem...

i'm not an expert but..

i don't see you restarting GPS in your code, so assuming you are doing it elsewhere, i think it takes some time to start it up and get a new position. i would assume you only want to start it up once.

and on the NDA, i don't think anyone is allowed to post any Apple code (even if you modified it).. although the NDA supposedly just changed.

again, i'm not an expert on either of these issues.

varchar
Oct 4, 2008, 01:40 PM
FYI.

I solved this issue... This is how:

In the newLocationUpdate(), I ONLY take the coordinates if it is accurate enough and it is new enough.



// Needed to filter cached and too old locations
if ((!currentLocation || currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) &&
(howRecent < -0.0 && howRecent > -10.0)) {
if (currentLocation)
[currentLocation release];

currentLocation = [newLocation retain];
}
}