2011-07-06 88 views
0

我想用iphone gps功能顯示用戶的當前位置,但問題是它給出了錯誤的位置。 當我放置在地圖上的銷釘,然後它丟棄銷在確切的位置,但是當我嘗試在文本中看到的位置,然後它給不準確的位置與500至800米approx.I我已經使用反向地理編碼和谷歌API,但都給予相同位置。請告訴我爲什麼發生這種情況,我如何顯示用戶的確切位置? 我的代碼是:iphone gps給出錯誤的位置

cllocationmanager *locationManager = [[CLLocationManager alloc] init]; 
     locationManager.delegate = self; 
     locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move 
     locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 100 m 
     [locationManager startUpdatingLocation]; 


    } 

    } 



- (void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation 

{ 


CLLocationCoordinate2D here = newLocation.coordinate; 
    NSLog(@"%f %f ", here.latitude, here.longitude); 


    MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:here]; 
    [geocoder setDelegate:self]; 
    [geocoder start]; 

     } 



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error{ 



} 



- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark 
{ 
    NSLog(@"The geocoder has returned: %@", [placemark addressDictionary]); 



    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[NSString stringWithFormat:@"%@",[placemark addressDictionary]] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
    [alertView show]; 
    [alertView release]; 


} 
+0

你可以說你是如何驗證位置?你是否正在使用具有不同數據的地圖? – JeremyP

回答

2

快速猜想:你檢查的CLLocation的水平精度?很多時候我得到的第一個反應是非常不準確的,然後隨後的調用會變得更好。

編輯:@pankaj首先,您能否確認這是一個準確性問題。如果這是我建議的問題,那麼CLLocation horizo​​ntalAccuracy將會很大。如果不是這種情況,那麼你可以忽略我的回答和這些評論。但是,如果horizo​​ntalAccuracy是一個很大的錯誤,那麼你將不得不等待更好的鎖定。有兩種方法可以做到這一點:

  1. 等一小段時間(一兩秒鐘),看看你是否有更好的鎖定。
  2. 更早開始請求位置,例如當應用程序啓動時,或需要位置的UIViewController啓動時。
+0

但我不能讓更新的位置,因爲我必須保存它。 –

+0

你是說你必須接受你收到的第一個輸入?如果是這樣,爲什麼? – jamie

+0

因爲我想獲取位置並將其發送到數據庫以搜索該位置的用戶。我無法花時間更新位置beacsuse沒有辦法告訴確切的位置將被更新的確切時間 –