2012-07-12 36 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