0
\$\begingroup\$

Typical tutorials suggest simple CoreLocation code similar to the following:

Header

#import<CoreLocation/CoreLocation.h>
@interface MyCLController : NSObject <CLLocationManagerDelegate> {
    CLLocationManager *locManager;
}
@property (nonatomic, retain) CLLocationManager *locManager;
@end

Setup

....
   self.locManager = [[[CLLocationManager alloc] init] autorelease];
   if(!self.locManager.locationServicesEnabled)
   {
       NSLog(@"User has opted out of location services");
   }

   self.locManager.delegate = self;
   self.locManager.desiredAccuracy = kCLLocationAccuracyBest;
   self.locManager.distanceFilter = 880.0f; // About 1/10th mile, in meters
   [self.locManager startUpdatingLocation];
....

Methods

- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
    // Respond to errors
    NSLog(@"Location manager error: %@", [error description]);
    return;
}

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"%@\n", [newLocation description]);
}

Deallocate

....
   [self.locManager release]
....

The above code works, but what common problems should I expect once I start testing on the most common iOS devices and versions? (assuming target of iOS 3.2 and above, building on iOS 4.3 SDK, code should work on all iOS devices that support at least 3.2 and any devices that support above 3.2)

Many simple examples online are 1-2 years old - are there improvements to the above that should be made due to changes in CoreLocation and the new devices released since 3.2?

What other suggestions would make the above more robust, and are there any other pitfalls developers should be aware of as they develop for CoreLocation?

\$\endgroup\$
3
\$\begingroup\$

Apple's LocateMe sample has been kept up to date and shows how to properly handle getting a fix with accuracy evalutation and timeout. It's quite an excellent sample so why not start there?

Devices without cellular won't have the benefit of cell triangulation but that's all abstracted anyway.

| improve this answer | |
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.