@property (nonatomic,strong) CLLocationManager *locManager;
这是我设置管理器的地方:
-(void) viewDidAppear:(BOOL)animated
{
self.locManager = [[CLLocationManager alloc] init];
[_locManager setDelegate:self];
[_locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[_locManager setPausesLocationUpdatesAutomatically:NO];
[_locManager setDistanceFilter:1.0];
[_locManager startUpdatingLocation];
}
这是我的委托(delegate)方法:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
lonLabel.text = longt;
}
该方法在启动时被调用三次,然后再也没有调用过。 预先感谢您
最佳答案
上述方法已弃用。 请使用这个委托(delegate)
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation* location = [locations lastObject];
latitude = location.coordinate.latitude;
longitude = location.coordinate.longitude;
[locationManager stopUpdatingLocation];
locationManager = nil;
}
关于ios - CLLocationManagerDelegate 方法未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22602323/