gpt4 book ai didi

ios - CLLocationManager 没有调用 didUpdateLocations

转载 作者:行者123 更新时间:2023-11-28 21:54:08 24 4
gpt4 key购买 nike

我一直无法弄清楚为什么位置管理器不向我提供更新。我已经添加了 key ,并在模拟器和设备上进行了测试。

编辑:STDOUT 还包含“委托(delegate):”

标准输出

2014-11-28 22:18:30.066 Speedo[14091:150298] Status: 4
2014-11-28 22:18:30.069 Speedo[14091:150298] Is when in use? 1
2014-11-28 22:18:30.158 Speedo[14091:150298] New status: 4
2014-11-28 22:18:30.159 Speedo[14091:150298] Is when in use? 1

FirstViewController.h

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface FirstViewController : UIViewController <CLLocationManagerDelegate>
@property (weak, nonatomic) IBOutlet UILabel* speedLabel;
@end

FirstViewController.cpp

#import "FirstViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface FirstViewController ()

@end

@implementation FirstViewController {
CLLocationManager *locationManager;
}


- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
self.speedLabel.text = @"";

if([locationManager respondsToSelector: @selector(requestWhenInUseAuthorization)]) {
[locationManager requestWhenInUseAuthorization];
}

// locationManager.desiredAccuracy = kCLLocationAccuracyBest;
// locationManager.distanceFilter = 0.01;
[locationManager startUpdatingLocation];

NSLog(@"Delegate: %@", locationManager.delegate);
NSLog(@"Status: %d", [CLLocationManager authorizationStatus]);
NSLog(@"Is when in use? %d", [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse);
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}

-(void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"New status: %d", status);
NSLog(@"Is when in use? %d", [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse);
[manager startUpdatingLocation];
}

-(void)locationManage: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {
CLLocation* last = [locations lastObject];
NSLog(@"Speed: %f m/s", last.speed); // meter per second
// TODO: support mutli-units
// m/s -> mph
// 1 -> 2.236
self.speedLabel.text = [NSString stringWithFormat:@"%d", (int)(last.speed * 2.23694)];
}

@end

最佳答案

也许这只是打字错误的结果。

-(void)locationManage: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {

应该是

-(void)locationManager: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {

您忘记了“locationManager”末尾的“r”。

关于ios - CLLocationManager 没有调用 didUpdateLocations,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27198645/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com