Reputation: 1177
I've been unable to figure out why location manager isn't providing updates to me. I've added the key, tested on simulator and on a device.
Edit: STDOUT also contains "Delegate: "
STDOUT
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
Upvotes: 0
Views: 569
Reputation: 37300
Perhaps it's just the result of a typo.
-(void)locationManage: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {
should be
-(void)locationManager: (CLLocationManager *)manager didUpdateLocations:(NSArray*)locations {
You forgot the "r" at the end of "locationManager".
Upvotes: 2