0

I try to update device's location course real time.

I am doing some experiment, and i make the VC as CLLocationManager's delegate. But when i run the app, the course information is not updating at all. i did set up a breakpoint in the delegate setting line, but the location manager is nil from the debugging area.

What is the problem?

#import "CourseInfomationViewController.h"

@interface CourseInfomationViewController ()

- (IBAction)startMoveLocation:(id)sender;

@end

@implementation CourseInfomationViewController
{
 CLLocationManager *_locationManager;
 CLLocation *_deviceLocation;

 double _deviceDirection;
 double _altitude;
 double _speed;

}

-(id)init {

if (self = [super init]) {

    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;
    _locationManager.desiredAccuracy =          kCLLocationAccuracyNearestTenMeters;




    //
    _deviceLocation = [[CLLocation alloc] init];

 }
 return self;
 }

 - (IBAction)startMoveLocation:(id)sender {


 [_locationManager startUpdatingLocation];

 }

  - (void)viewDidLoad {
 [super viewDidLoad];

  }

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

#pragma mark - location Delegate

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



_deviceLocation = [locations lastObject];
_altitude = _deviceLocation.altitude;
_deviceDirection = _deviceLocation.course;
_speed = _deviceLocation.speed;

NSLog(@"altitude is %f", _altitude);
NSLog(@"altitude is %f", _deviceDirection);
NSLog(@"altitude is %f", _speed);

}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {

  NSLog(@"%@", error);
}
Ekta Padaliya
  • 5,743
  • 3
  • 39
  • 51
Nan
  • 496
  • 3
  • 21
  • 1
    keep your location manager strong reference – Prashant Tukadiya Jun 28 '16 at 10:06
  • You aren't requesting `whenInUseAuthorization`. @MikeAlter iVars are strong but a strong property is better style than using an iVar – Paulw11 Jun 28 '16 at 10:09
  • guys, can you explain that in detail, i am on beginner level. :) i read the apple office document, they did not mention the whenInUseAuthorization stuff – Nan Jun 28 '16 at 10:10
  • Please refer to my answer here: http://stackoverflow.com/questions/31682999/for-google-maps-ios-sdk-current-location-occasionally-gets-plotted-at-0-0/31739219#31739219 – Bharat Jun 29 '16 at 10:46

0 Answers0