1

背景:我想让用户在他们想要的时候在几秒钟内得到他们的位置。但是,位置大多是不准确的。我想询问用户是否愿意再试一次以获得更准确的地址。

问题:如何编码以保证下一个猜测总是比上一个猜测更好。

我试过的:

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;
            }
        }
    }];
}

更新 当用户再次询问时,猜测可能需要更长的时间。我只是想知道我应该如何编码。IE:我应该[[self locationManager] startUpdatingLocation];再打电话吗?还是会重置我到目前为止的位置。因此,如何根据 GPS 拥有的当前信息第二次改进我的猜测(GPS 开启时间越长,准确度就越高?)。

4

1 回答 1

1

对于通过代码的准确性,您无能为力...除了

   [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

您已经完成了...据我所知,如果您使用的是 3G 或 EDGE,那么您的精度会大大提高(可以达到 5-10m 的精度水平)。

您可以参考Apple 的这篇文章,其中讨论了 iphone GPS 精度的工作原理......

希望这有帮助..

于 2012-04-12T16:18:22.977 回答