2010-12-06 62 views
0

正如我需要一張地圖我使用的代碼的當前位置:問題在iPhone SDK中得到一個地圖的當前位置

locationManager = [[CLLocationManager alloc] init]; 
     locationManager.delegate = self; 
     locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; 

     [locationManager setDistanceFilter:10]; 
     [locationManager startUpdatingLocation]; 

我正在錯誤的didFailWithError methos爲:

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    printf("\nXXXXXXXXXXXXXXXXXXXXXXXXXX Inside didFailWithError in locationmanager method XXXXXXXXXXXXXXXXXXXXXXXXXX"); 
    NSLog(@"Error: %@", error); 
} 

,我在我的控制檯收到錯誤信息如下:

XXXXXXXXXXXXXXXXXXXXXXXXXX Inside didFailWithError in locationmanager method XXXXXXXXXXXXXXXXXXXXXXXXXX2010-12-06 17:58:12.335 ParkingAreaLocator[6992:207] Error: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" 

和WiFi上。

我沒有在模擬器和設備4.0 sdk中獲取當前位置。

任何人都可以幫助我如何解決這個問題。

謝謝 Monish

+0

你有沒有嘗試,爲什麼精度較差? – 2010-12-06 12:44:18

回答

0

kCLErrorDomain = 0表示kCLErrorLocationUnknown

位置管理器無法馬上獲得一個位置值。

如果位置服務無法立即檢索位置修復,它會報告kCLErrorLocationUnknown錯誤並繼續嘗試。在這種情況下,您可以簡單地忽略錯誤並等待新事件。

嘗試用更少的準確性

+0

感謝您的建議。可否請告訴我「儘量少嘗試」是指? – 2010-12-06 12:56:16

0

這是更簡單了很多比你正在做的。我從標題中假設你在視圖中有一個MKMapView?如果是這樣,您可以使用它來獲取用戶的位置。

在你的.h中,有這個視圖控制器採用協議。

然後在.M,這樣做:

void viewDidLoad() 
{ 
    ... 
    myMapView.showsUserLocation = YES; 
    ... 
} 


(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)location 
{ 
    //Do whatever! that MKUserLocation is the location the map view just determined. 
}