Я довольно новичок в объективной разработке 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
извините, это ошибка. Одиночный c не находится в фактическом коде. – Khledon
@ user3254994 Я обновил с ответом – kevin
Спасибо, что это была проблема – Khledon