Я только начал писать код в Objective C и создаю приложение, которое будет отслеживать местоположение пользователей и отправлять оповещения с последними данными.Этот код ни в коем случае не завершен, но я столкнулся с проблемой при попытке использовать переменную, которую я создал "lat" в "viewDidLoad" для предупреждения.Я объявил переменную в делегате / методе CLLocationManager (я действительно не знаю, как она называется), и я не знаю, как использовать ее в других местах.
- (void)viewDidLoad
{
locationManager =[[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 100.0f;
[locationManager startUpdatingLocation];
UIAlertView *message = [[UIAlertView alloc] initWithTitle: @"Your current Latitude is:"
message:This is where I want to put the variable "lat"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) locationmanager: (CLLocationManager *) manager
didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation
{
NSString *lat = [[NSString alloc] initWithFormat: @"%g",newLocation.coordinate.latitude];
NSString *lng = [[NSString alloc] initWithFormat:@"%g", newLocation.coordinate.longitude];
}
Буду признателен за любую помощь!