1

Please take it easy on me. I'm a newbie and is trying to learn mapkit. Just wondering if you can help me find my way with this one.. I have a function which find the coordinate in AppViewController.m

  • (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    CLLocationCoordinate2D location = [newLocation coordinate]; NSString *lat = [[NSString alloc] initWithFormat:@"%f", loc.latitude]; latitude.text = lat; ...

}

My question is, is there a way I can access the variable lat, say something like declaring it as a global varaible, from function - (void) viewDidLoad { ... }

This might sound a stupid question for most of you, but please give me a hint.. I've been reading about singleton.. but couldn't understand how I can use implement this in this one.

Kind Regards, David

1 Answer 1

2

You have to make lat an instance variable. Declare it in your class's @interface section, then you can access it from any method inside the class.

@interface AppViewController : UIViewController
{
    NSString *lat;
}

...

@end
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Ole, thank you for your reply. I did try that too but when I try to use lat in - (void) viewDidLoad { ... } the value of lat is null; Any further suggestion?
Sure, probably because viewDidLoad is called first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.