【问题标题】:iOS: get Accurate Reverse Geocoding using CLLocationManager?iOS:使用 CLLocationManager 获得准确的反向地理编码?
【发布时间】:2012-04-25 00:36:13
【问题描述】:

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

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

我尝试过的:

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 开启时间越长,准确度就越高?)。

【问题讨论】:

    标签: iphone ios gps location cllocationmanager


    【解决方案1】:

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

       [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    

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

    您可以参考 Apple 的 this 文章,该文章讨论了 iphone GPS 精度的工作原理......

    希望这会有所帮助..

    【讨论】:

    • 感谢您的链接。我不敢说它无助于回答我的问题。请参阅我更新的问题进行澄清。
    • 无法保证准确性会随着时间或位置管理器的未来更新而增加。它甚至可能会下降..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 2012-08-30
    • 2015-07-27
    相关资源
    最近更新 更多