2012-04-12 6 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が現在持っている情報に基づいて2回目の推測を改善するにはどうすればよいですか?

答えて

1

くらいあなたはまだ行っている

[locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 

から離れて...コードを経由して精度に関してできることは何もありません... 限りあなたは3GやEDGEよりも上にある場合、私が見てきたように精度が大幅に向上します(5〜10mの精度レベルが達成できます)。

あなたはiPhoneのGPSの精度がどのように機能するかを語るアップルによってthisの記事を参照することができます...このことができます願って

..

+0

は、リンクいただきありがとうございます。私はそれが私の質問に答えるのに役立つとは言いがたいです。明確にするために私の更新された質問を参照してください。 – Byte

+1

時間の経過とともに、またはロケーションマネージャからの今後のアップデートで精度が向上するという保証はありません。 –

関連する問題