I am trying to perform a simple operation that i have done alot in this program. I am trying to launch the CLLocationManager once the app is finished launching and get the current location once the update has happened. My app works in that it get the current location, when i NSLog the current location it works fine. The problem is that i am trying to pass this location from one object to another and it does not have a value once it gets there.
I have been looking up accessor methods and everything seems right as i have these types of operations all over my program. I have tried to follow numerous examples but none seem to work.
Here is some code.
This is the .h file of the CLLocationManagerDelegate.
@interface YogaAllianceAppDelegate : NSObject <UIApplicationDelegate,CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocation *mycurrentLocation;
float curLats;
float curLons;
BOOL locationDidUpdate;
UIWindow *window;
YogaAllianceViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) float curLats;
@property (nonatomic, assign) float curLons;
@property (nonatomic, assign) CLLocation *mycurrentLocation;
@property (nonatomic, retain) IBOutlet YogaAllianceViewController *viewController;
@end
This is the .m file
@synthesize viewController, locationManager, curLats, curLons, mycurrentLocation;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
self.locationManager = [[[CLLocationManager alloc]init] autorelease];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
locationDidUpdate = NO;
[window addSubview:viewController.view];
[window makeKeyAndVisible];
}
-(void)locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *)newLocation
fromLocation: (CLLocation *)oldLocation{
[[NSNotificationCenter defaultCenter]
postNotificationName:@"currentLocationDidUpdate" object: self];
[locationManager stopUpdatingLocation];
NSLog(@"Core Location says location available");
self.curLats = newLocation.coordinate.latitude;
self.curLons = newLocation.coordinate.longitude;
self.mycurrentLocation = newLocation;
NSLog(@"current position is then %@", [mycurrentLocation description]);
}
At this point it works. I get the location printed out and everything, but i need that location in another object and it seems that all my attempts at reworking the dot notation has failed. Here is the . h of the object i need it in.
@interface School_Location_List_Controller : UIViewController {
CLLocation* currentLocation;
}
- (IBAction) btnBack_Clicked:(id)sender;
@property (nonatomic, assign) CLLocation* currentLocation;
And here is the .m
@implementation School_Location_List_Controller
@synthesize destinations, closeSchools, currentLocation;
-(void) viewWillAppear: (BOOL)animated {
NSLog (@"Registered for location events");
YogaAllianceAppDelegate *updated = [[YogaAllianceAppDelegate alloc]init];
currentLocation = updated.mycurrentLocation ;
NSLog(@"current position here in the passed object is %@", [currentLocation description]);
[super viewWillAppear:animated];
}
It is at this point that i am confused. When i print that out, it just says the currentLocation is Null. Its like it never got the data..
Thank you guys in advance.