2012-07-12 33 views
0

我添加了查找位置的代碼,這是在模擬器上工作,但它不適用於iPhone設備。我已啓用位置服務,但仍然無法正常工作。無法在iPhone設備上找到位置

-(void)firstTimeRefresh { 

CLLocation *bestLocation = [[[AppDelegate getAppDelegate] locationManager] bestLocation]; 
if (bestLocation != NULL) { 
    NSLog(@"Using Best Loaction"); 
    [self getArray: [NSArray arrayWithObjects: [NSNumber numberWithFloat:bestLocation.coordinate.latitude], 
         [NSNumber numberWithFloat: bestLocation.coordinate.longitude], nil] :@"false":page_no]; 
} 
} 

回答

1

嘗試此代碼及其在我的工作結束。

locationManager = [[CLLocationManager alloc] init]; 
[locationManager setDelegate:self]; 
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; 
[locationManager startUpdatingLocation]; 

定義CLLocationManagerDelegate代表在.H類文件 位置時更新此功能將被調用。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { 
} 
+0

它仍然不能正常工作 – Pallavi 2012-07-12 07:48:31

+0

你正在運行的模擬器或設備的代碼? – 2012-07-12 07:54:22

+0

代碼在模擬器上正常運行,但沒有在設備上安裝該應用程序 – Pallavi 2012-07-12 09:02:25