我添加了查找位置的代码,这是在模拟器上工作,但它不适用于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];
}
}
答案 0 :(得分: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 { }