2012-04-12 75 views
1

背景:我想讓用戶在他們想要的時間內能夠在幾秒內獲得他們的位置。但是,這個位置大部分是不準確的。我想詢問用戶是否想再次嘗試更準確的地址。iOS:使用CLLocationManager獲取準確的反向地理編碼?

問題:如何進行編碼,以確保下一次猜測始終比上次猜測更好。

我曾嘗試:

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越長,精度越好?)。

回答

1

有沒有什麼你可以通過有關碼精確從

[locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 

做......除了你已經做了... 至於如果你是3G或EDGE我還從沒見過您的準確度顯着提高(可達到5-10m的準確度)。

你可以參考蘋果this物品,其講話的iPhone的GPS精確度是如何工作的?

希望這有助於..

+0

謝謝你的鏈接。我恐怕不能回答我的問題。請參閱我的更新問題以進行澄清。 – Byte 2012-04-12 16:25:48

+1

無法保證準確性會隨着時間或地理位置經理即將到來的更新而增加..它甚至可能會下降.. – 2012-04-12 16:28:50

相關問題