标题更新时,CoreLocation位置不会更新

时间:2012-11-13 17:10:19

标签: ios core-location

我需要得到位置和标题。一旦我运行我的代码,我只获得标题更新,位置不会更新,因为它不会出现在日志中。

如果我禁用标题更新,我会得到我的位置坐标。 如果标题更新打开,我没有获得位置。 有没有人遇到过同样的问题?

这是我的设置例程和我的方法:

locationManager = [[CLLocationManager alloc]init];
locationManager.headingFilter = 1;
locationManager.delegate = self;

[locationManager startUpdatingLocation];
[locationManager startUpdatingHeading];

 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation//          fromLocation:(CLLocation *)oldLocation 
{NSString *currentLatitude = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.latitude];
NSLog(@"currentLatitude = %@", currentLatitude);

NSString *currentLongitude = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
NSLog(@"currentLongitude = %@", currentLongitude);

NSString *currentHorizontalAccuracy = [[NSString alloc] initWithFormat:@"%g", newLocation.horizontalAccuracy];
NSLog(@"currentHorizontalAccuracy = %@", currentHorizontalAccuracy);

NSString *currentAltitude = [[NSString alloc] initWithFormat:@"%g", newLocation.altitude];
NSLog(@"currentAltitude = %@", currentAltitude);

NSString *currentVerticalAccuracy = [[NSString alloc] initWithFormat:@"%g", newLocation.verticalAccuracy];
NSLog(@"currentVerticalAccuracy = %@", currentVerticalAccuracy);
}- (BOOL)locationManagerShouldDisplayHeadingCalibration: (CLLocationManager *)manager {
return NO;}


     -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
CLLocationDirection trueHeading = newHeading.trueHeading;}

1 个答案:

答案 0 :(得分:0)

该位置尚未更新,因为该方法已在ios 6.0中更新

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation* location = [locations lastObject];

这就是didUpdateLocations的样子,现在需要一个数组。 [locations lastObject]这是数组中最后知道的位置。从中你可以得到坐标。