I have a this function to grab the lat and long in my app delegate, and it’s working fine:
- (void)newPhysicalLocation:(CLLocation *)location {
// Store for later use
self.lastKnownLocation = location;
// Remove spinner from view
for (UIView *v in [self.viewController.view subviews])
{
if ([v class] == [UIActivityIndicatorView class])
{
[v removeFromSuperview];
break;
}
}
// Alert user
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Location Found" message:[NSString stringWithFormat:@"Found physical location. %f %f", self.lastKnownLocation.coordinate.latitude, self.lastKnownLocation.coordinate.longitude] delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
currentLatitude = (self.lastKnownLocation.coordinate.latitude);
NSLog(@"current latitude: %f",self.lastKnownLocation.coordinate.latitude);
currentLongitude = (self.lastKnownLocation.coordinate.longitude);
NSLog(@"current longitude: %f",currentLongitude);
}
However, I’m trying to send the currentLatitude and currentLongitude values to the top of the app delegate in the didFinishLaunchingWithOptions section. I’m trying to do this so I can pass those values to another viewController in which I have set up:
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
Can I send the currentLatitude and currentLongitude values to the didFinishLaunchingWithOptions section?
From what I understood from your question, you want to pass those coordinate values to another view controller. If thats the case u can make the
currentLatitudeandcurrentLongitudeas class variables of the app delegate. Then when u call this function inapplicationDidFinishLaunchingWithOptions:you can assign the values to these class variables. Then u can access these variables anywhere through an instance of the app delegate.Note: You have to synthesize the variables if u want to access them outside the class.
Hope this helps