2014-01-30 1 views
0

Я довольно новичок в объективной разработке c.Objective-C Место для маркировки текста

Я пытаюсь получить координаты долготы и широты и назначить метки.

Однако при загрузке приложения мои ярлыки не обновляются с помощью координат.

Я уверен, что делаю что-то очень простое, но любая помощь будет принята с благодарностью!

.h:

#import <UIKit/UIKit.h> 
#import <CoreLocation/CoreLocation.h> 
#import "ViewController.h" 

@interface StartCycleViewController : UIViewController <NSXMLParserDelegate, CLLocationManagerDelegate> 
@property (weak, nonatomic) IBOutlet UILabel *longitudeLabel; 
@property (weak, nonatomic) IBOutlet UILabel *latitudeLabel; 
@property (nonatomic,strong) CLLocation *currentCycleLocation; 
@property (nonatomic,strong) CLLocationManager *cycleLocation; 

- (void) stopLocationManager; 


@end 

.m:

#import "StartCycleViewController.h" 

@interface StartCycleViewController() 

@end 

@implementation StartCycleViewController 

@synthesize cycleLocation = _cycleLocation; 
@synthesize currentCycleLocation = _currentCycleLocation; 


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self startCycleLocation]; 
    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


#pragma mark - startCycleLocation 

- (void)startCycleLocation{ 

    if (!_cycleLocation){ 
     _cycleLocation = [[CLLocationManager alloc]init]; 
     _cycleLocation.desiredAccuracy = kCLLocationAccuracyBestForNavigation; 
     _cycleLocation.distanceFilter = 10; 
     _cycleLocation.delegate = self; 

    } 
    [_cycleLocation startUpdatingLocation]; 

} 

-(void) cycleLocation:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
     fromLocation:(CLLocation *)oldLocation { 

    NSLog(@"didUpdateToLocation: %@", newLocation); 
    CLLocation *currentLocation = newLocation; 

    if (currentLocation != nil) { 
     self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f",   currentLocation.coordinate.longitude]; 
     self.latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; 
    } 

} 


- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { 
    NSLog(@"%@",error); 

    if ([error code] != kCLErrorLocationUnknown){ 
     [self stopLocationManager]; 
    } 
} 

- (void) stopLocationManager { 
    [self.cycleLocation stopUpdatingLocation]; 
} 

@end 

ответ

0

Я бы оставил это как комментарий, но я не имею репутацию, чтобы сделать это.

Что происходит в строке, где вы обновляете этикетку?

self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f",  c currentLocation.coordinate.longitude]; 

Почему этот одинокий c?

EDIT: Так я понял, этот метод

-(void) cycleLocation:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 

никогда не вызывался. После того, как копаться я видел метод должен быть вместо этого:

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

Заменить старую подпись с этим один и он должен работать.

+0

извините, это ошибка. Одиночный c не находится в фактическом коде. – Khledon

+0

@ user3254994 Я обновил с ответом – kevin

+0

Спасибо, что это была проблема – Khledon

Смежные вопросы