我想創建簡單的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];
}
你的問題是什麼? – jv42 2010-10-21 12:21:20
我無法獲取經度和緯度值。我知道應該有一些默認值,因爲這是模擬器。但我無法得到它們。我的問題是爲什麼方法「didUpdateToLocation」永遠不會被調用?我在這裏錯過了什麼嗎? – 1110 2010-10-21 12:38:38