0

我添加了查找位置的代码,这在模拟器上工作,但在 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];
} 
}
4

1 回答 1

1

试试这个代码和它在我的工作。

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

在更新位置时,在 .h 类文件中定义 CLLocationManagerDelegate 委托,此函数将被调用。

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
}
于 2012-07-12T07:02:46.190 回答