1

Background: I want to allow users to get their location within seconds when they want it. However, the location is mostly inaccurate. I want to ask the user to if they would like to try again for a more accurate address.

Question: How to code such that it guarantees that the next guess, is always better than the last guess.

What I have tried:

CLLocationManager *locationManager;

- (CLLocationManager *)locationManager {
    if (locationManager != nil) {
        return locationManager;
    }
    locationManager = [[CLLocationManager alloc] init];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager setDelegate:self];
    return locationManager;
}

-(void)myLocationClickedWithCount: (int) count{
    [[self locationManager] startUpdatingLocation];
    CLLocation *location = [locationManager location];
    CLGeocoder *locationGeocoded = [[CLGeocoder alloc] init];
    [locationGeocoded reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        if (!placemark){
            if (count > 0){
                //placemark not available, try again after 1 second
                sleep(1);
                [self myLocationClickedWithCount:count-1];
            }
            else{
                //Unable to get location after 3 tries
                UIAlertView *locationNotFoundAlert = [[UIAlertView alloc]initWithTitle:@"Unable to Locate" message:@"Would you like to try again?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
                locationNotFoundAlert.tag = locationNotFoundAlertTag;
                [locationNotFoundAlert show];
            }
        }else{
            // got location but not accurate.
            if (location.horizontalAccuracy > accuracyRadius) {
                UIAlertView *locationInaccurateAlert = [[UIAlertView alloc]initWithTitle:@"Inaccurate Location" message:[NSString stringWithFormat:@"Your GPS shows the radius of %.2f meters. Would you like to try again?",location.horizontalAccuracy] delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
                locationInaccurateAlert.tag = locationInaccurateAlertTag;
                [locationInaccurateAlert show];
            }else {
                address.text = placemark;
            }
        }
    }];
}

Update When the user asks again, it can take a little longer to guess. I just want to know how I should code it. IE: Should I call [[self locationManager] startUpdatingLocation]; again? or will that reset my location so far. Hence, how can i improve my guess the second time based on the current information GPS has (the longer GPS is on, the better accuracy right?).

1 Answer 1

1

there is nothing much you can do regarding accuracy via code... apart from

   [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

which you have already done... As far as I have seen if you are on 3G or EDGE than your accuracy increases considerably (accuracy level of 5-10m can be achieved).

you can refer this article by Apple which talks how the iphone GPS accuracy works...

hoping this helps..

2
  • Thank you for the link. I am afraid to say that it does not help answer my question. Please refer to my updated question for clarification.
    – Byte
    Apr 12, 2012 at 16:25
  • 1
    there is no guarantee that the accuracy will increase with time or in the coming updates from the location manager.. it might even go down.. Apr 12, 2012 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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