2010-10-21 76 views
0

我想創建簡單的GPS應用程序只是爲了在模擬器中顯示簡單的數據。我沒有錯誤就是無法獲取數據。 「didFailWithError」方法是我可以工作的唯一方法:),這是代碼:iPhone GPS問題模擬器沒有反應

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

lm = [[CLLocationManager alloc] init]; 
if([CLLocationManager locationServicesEnabled]) 
{ 
    lm.delegate = self; 
    lm.desiredAccuracy = kCLLocationAccuracyBest; 
    //lm.distanceFilter = 1000.0f; 
    [lm startUpdatingLocation]; 
} 

} 


- (void) locationManager: (CLLocationManager *) manager 
didUpdateToLocation: (CLLocation *) newLocation 
fromLocation: (CLLocation *) oldLocation{ 
NSString *lat = [[ NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude]; 
txtLatitude.text = lat; 

NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude]; 
txtLongitude.text = lng; 

NSString *acc = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy]; 
txtAccuracy.text = acc; 

[acc release]; 
[lat release]; 
[lng release]; 
} 
- (void) locationManager:(CLLocationManager *)manager 
didFailWithError: (NSError *) error 
{ 
NSString *msg = [[NSString alloc] initWithString:@"Error obtaining location"]; 
UIAlertView *alert = [[ UIAlertView alloc] initWithTitle:@"Error" 
       message:msg 
      delegate:nil 
      cancelButtonTitle:@"Done" 
      otherButtonTitles:nil]; 
[alert show]; 
[msg release]; 
[alert release]; 
} 
+0

你的問題是什麼? – jv42 2010-10-21 12:21:20

+0

我無法獲取經度和緯度值。我知道應該有一些默認值,因爲這是模擬器。但我無法得到它們。我的問題是爲什麼方法「didUpdateToLocation」永遠不會被調用?我在這裏錯過了什麼嗎? – 1110 2010-10-21 12:38:38

回答

2

它不會在模擬器中移動。

http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iphone_development/125-Using_iPhone_Simulator/iphone_simulator_application.html

「的核心位置功能

通過在模擬器CoreLocation框架報告重定位固定在以下座標(精度100米),其對應於1無限循環,加利福尼亞Cupertino 95014 。

緯度:37.3317北 經度:122.0307西」

你可以嘗試添加一個簡單的隨機或定時事件,平s didUpdate ...方法顯式地使用您的首選項的假數據。

+0

我寫這段代碼。在didUploadToLocation方法中使用斷點運行此代碼。但代碼永遠不會到達那裏。總是以失敗的方式完成。這是爲什麼發生? – 1110 2010-10-22 06:23:37

+0

什麼是失敗原因 – 2010-10-22 14:58:54

+0

沒有理由只是didUpUpload方法不會被調用。 – 1110 2010-10-25 06:31:26