iOS:使用CLLocationManager获取准确的反向地理编码? [英] iOS: get Accurate Reverse Geocoding using CLLocationManager?

查看:228
本文介绍了iOS:使用CLLocationManager获取准确的反向地理编码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我希望用户在需要时能够在几秒钟内获得他们的位置。但是,这个位置大部分是不准确的。我想询问用户是否想再次尝试更准确的地址。



问题:如何进行编码以确保下一次猜测始终优于上次猜测。



我曾尝试过:

  CLLocationManager * locationManager; 

- (CLLocationManager *)locationManager {
if(locationManager!= nil){
return locationManager;
}
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
返回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){
//地标不可用,1秒后再试
sleep(1);
[self myLocationClickedWithCount:count-1];
}
else {
// 3次尝试后无法获取位置
UIAlertView * locationNotFoundAlert = [[UIAlertView alloc] initWithTitle:@Unable to Locate消息:@会你想再试一次? delegate:self cancelButtonTitle:@NootherButtonTitles:@Yes,nil];
locationNotFoundAlert.tag = locationNotFoundAlertTag;
[locationNotFoundAlert show];
}
} else {
//得到位置但不准确。
if(location.horizo​​ntalAccuracy> accuracyRadius){
UIAlertView * locationInaccurateAlert = [[UIAlertView alloc] initWithTitle:@Inaccurate Location消息:[NSString stringWithFormat:@您的GPS显示半径%。 2f米,你想再试一次吗?,location.horizo​​ntalAccuracy] delegate:self cancelButtonTitle:@NootherButtonTitles:@Yes,nil];
locationInaccurateAlert.tag = locationInaccurateAlertTag;
[locationInaccurateAlert show];
} else {
address.text = placemark;
}
}
}];






更新
当用户再次询问时,猜测时间可能会稍长一些。我只是想知道我应该如何编码。 IE:我应该再次打电话给 [[self locationManager] startUpdatingLocation]; 吗?或者会重置我的位置到目前为止。因此,如何根据当前的GPS信息第二次提高我的猜测(GPS的时间越长,准确性越好?)。

解决方案

:kCLLocationAccuracyBest];

你已经完成了...
据我所见,如果你是在3G或EDGE上比你的准确度大幅度提高(准确度可以达到5-10m)。


你可以参考

希望这帮助..


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?).

解决方案

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..

这篇关于iOS:使用CLLocationManager获取准确的反向地理编码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆