views:

78

answers:

2

Im trying to get the lat and long values generated in a void function and use them within another function. Any help grateful.

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
 float latDeg = newLocation.coordinate.latitude;
 NSLog(@"Lat: %g", latDeg);

 float longDeg = newLocation.coordinate.longitude;
 NSLog(@"Lat: %g", longDeg);
}

I want to use the latDeg and longDeg variables.

+2  A: 

Declare latDeg and longDeg as instance variables in your class. Declaring properties for the instance variables and using them for every access of the variable is optional, but recommended.

Ole Begemann
A: 

If you want to reuse them in the same class, you can just declare them after implementation of you class. For example `@implementation LocationClass float latDeg; float longDeg

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { latDeg = newLocation.coordinate.latitude; NSLog(@"Lat: %g", latDeg);

    longDeg = newLocation.coordinate.longitude; NSLog(@"Lat: %g", longDeg); } ` that's enough. Or you can declare them in you AppDelegater and then use them like:

    YourAppDelegate delegate; delegate = (YourAppDelegate) [[UIApplication sharedApplication] delegate]; float currVar = [delegate->longDeg];

Kirill SIMAGIN