0

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

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

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

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;}
4

1 回答 1

0

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

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

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

于 2012-11-14T15:28:58.033 回答