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)locationManagerCLLocationManager *)manager
didUpdateToLocationCLLocation *)newLocation
fromLocationCLLocation *)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 *) currentLongitudeNSString *) currentLongitudeDirection {
[activityIndicator startAnimating];
myCurrentLatitude= currentLatitude;
myCurrentLongitude = currentLongitude;
[[MyCLController sharedInstance].locationManager stopUpdatingLocation];
}
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)locationManagerCLLocationManager *)manager
didUpdateToLocationCLLocation *)newLocation
fromLocationCLLocation *)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 *) currentLongitudeNSString *) currentLongitudeDirection {
[activityIndicator startAnimating];
myCurrentLatitude= currentLatitude;
myCurrentLongitude = currentLongitude;
[[MyCLController sharedInstance].locationManager stopUpdatingLocation];
}