Zword,
Can you post the code you are having trouble with and we can try to assist in debugging it?
In the meantime, here is code which works well:
Header
Code:
@interface MyTestGPSViewController : UIViewController <CLLocationManagerDelegate> {
NSString *myCurrentLatitude;
NSString *myCurrentLongitude;
CLLocationManager *locationManager;
CLLocation *currentLocation;
}
@property(nonatomic,retain) NSString *myCurrentLatitude;
@property(nonatomic,retain) NSString *myCurrentLongitude;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) CLLocation *currentLocation;
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
@end
Implementation
(contains only excerpt of related code for GPS)
Code:
- (id) init {
self = [super init];
if (self != nil) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
}
// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSDate* newLocationeventDate = newLocation.timestamp;
NSTimeInterval howRecentNewLocation = [newLocationeventDate timeIntervalSinceNow];
// NSDate* oldLocationeventDate = newLocation.timestamp;
//NSTimeInterval howRecentOldLocation = [oldLocationeventDate timeIntervalSinceNow];
// Needed to filter cached and too old locations
if ((!currentLocation || currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) &&
(howRecentNewLocation < -0.0 && howRecentNewLocation > -10.0)) {
if (currentLocation)
[currentLocation release];
currentLocation = [newLocation retain];
}
}
return self;
}