iphone - CLLocation header is always -1 -


hey guys, trying build app use compass point in direction of predetermined location, trying understand how make basic compass. followed guide, "-1" header, , have gotten work once, , haven't changed code since. ideas helpful.

#import <uikit/uikit.h> #import <corelocation/corelocation.h>  @interface trackerviewcontroller : uiviewcontroller <cllocationmanagerdelegate> {  }  @property (nonatomic, retain) cllocationmanager *locationmanager; @property (nonatomic, retain) iboutlet uiswitch *toggle; @property (nonatomic, retain) iboutlet uiimageview *compass; @property (nonatomic, retain) iboutlet uilabel *headinglabel;  -(ibaction)toggleswitch;  @end 

and implementation file...

#import "trackerviewcontroller.h"   @implementation trackerviewcontroller  @synthesize locationmanager;  @synthesize toggle;  @synthesize compass;  @synthesize headinglabel;  - (ibaction)toggleswitch { if(self.toggle.ison) {     [self.locationmanager startupdatingheading]; } else {     [self.locationmanager stopupdatingheading]; } }  - (void)viewwillappear:(bool)animated { [super viewwillappear:animated];  if ([cllocationmanager headingavailable]) {     self.locationmanager = [[[cllocationmanager alloc] init] autorelease];      self.locationmanager.delegate = self; } else {     [[[[uialertview alloc] initwithtitle:@"aw snap!"                                   message:@"device doesn't support heading updates"                                  delegate:nil                         cancelbuttontitle:@"ok"                         otherbuttontitles:nil] autorelease] show];    } }  - (void)locationmanager:(cllocationmanager *)manager didupdateheading:(clheading  *)newheading { float heading = [newheading trueheading] * m_pi / 180.0; self.compass.transform = cgaffinetransformmakerotation(-heading); self.headinglabel.text = [nsstring stringwithformat:@"%d°", (int)[newheading trueheading]]; nslog(@"%d", (int)[newheading trueheading]); }   - (void)locationmanager:(cllocationmanager *)manager     didfailwitherror:(nserror *)error {  //  nslog(@"error!");  if (error.code == kclerrordenied) {     [[[[uialertview alloc] initwithtitle:@"aw snap!"                                   message:@"user didn't allow heading updates"                                  delegate:nil                         cancelbuttontitle:@"ok"                         otherbuttontitles:nil] autorelease] show];     self.toggle.on = no;     [self.locationmanager stopupdatingheading]; } }   - (void)didreceivememorywarning { // releases view if doesn't have superview. [super didreceivememorywarning];  // release cached data, images, etc aren't in use. }  - (void)viewdidunload { // release retained subviews of main view. // e.g. self.myoutlet = nil; }   - (void)dealloc { self.locationmanager = nil; self.compass = nil; self.toggle = nil; self.headinglabel = nil; [super dealloc]; }  @end 

magneticheading value in property represents heading relative magnetic north pole, different geographic north pole. value 0 means device pointed toward magnetic north, 90 means pointed east, 180 means pointed south, , on. value in property should valid.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -