views:

242

answers:

2

Hi Everyone:

I recall reading somewhere (I forget where) that if an iPhone application simply ran the CLLocationManager once, it didn't come up with the most accurate results. Is this accurate, and if so, how can I combat this problem? I want to come up with the most accurate GPS results, and am wondering if only one time will create the best results.

Thanks for any help!

A: 

What you read was likely from the iPhone Application Programming Guide:

To retrieve the user’s current location, create an instance of the CLLocationManager class and configure it with the desired accuracy and threshold parameters. To begin receiving location notifications, assign a delegate to the object and call the startUpdatingLocation method to start the determination of the user’s current location. When new location data is available, the location manager notifies its assigned delegate object. If a location update has already been delivered, you can also get the most recent location data directly from the CLLocationManager object without waiting for a new event to be delivered.

[...]

Checking the timestamp of an event is recommended because the location service often returns the last cached location event immediately. It can take several seconds to obtain a rough location fix so the old data simply serves as a way to reflect the last known location. You can also use the accuracy as a means of determining whether you want to accept an event. As it receives more accurate data, the location service may return additional events, with the accuracy values reflecting the improvements accordingly.

Ben S
+2  A: 
CLLocationManager *locationManager.desiredAccuracy = kCLLocationAccuracyBest;

Will return the best possible result for you. The delegate method

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation

will continue to return the user's location based on the accuracy preferences you have set.

If you only need the location once, you need to remember to call stopUpdatingLocation on self. If you need to update the user's location continuously, do not call stopUpdatingLocation

I am using CoreLocation to get a user's location, and it's quite accurate for my use.

Canada Dev