0
저는 여전히 xcode와 전체 목표 인 초보 개발자입니다.레이블의 위치 정확도
내가 캔트 좌표가 얼마나 정확하게 볼 수 있습니다 (시작 단계에서의 계속) 화면에 좌표를 볼 수있는 응용 프로그램
그러나 사용자를 만드는 중이라서 ... 내가 디버그 영역에서 볼 수 있습니다 , 그러나 응용 프로그램을 사용하는 사용자는 그것을 볼 수 없습니다.
코드에 어떻게 추가합니까?
내 코드 현재 :
#import "CurrentLocationViewController.h"
@interface CurrentLocationViewController()
@end
@implementation CurrentLocationViewController
{
CLLocationManager *_locationManager;
CLLocation *_location;
BOOL _updatingLocation;
NSError *_lastLocationError;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self updateLabels];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)getLocation:(id)sender
{
[self startLocationManager];
[self updateLabels];
}
- (id) initWithCoder:(NSCoder *)aDecoder
{
if ((self = [super initWithCoder:aDecoder])) {
_locationManager = [[CLLocationManager alloc] init];
}
return self;
}
프라그 마크 - CLLocationManagerDelegate
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"did fail with error %@",error);
if (error.code == kCLErrorLocationUnknown) {
return;
}
[self stopLocationManager];
_lastLocationError = error;
[self updateLabels];
}
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = [locations lastObject];
NSLog(@"didUpdateLocations %@", newLocation);
_lastLocationError = nil;
_location = newLocation;
[self updateLabels];
}
- (void) updateLabels
{
if (_location !=nil) {
self.latitudeLabel.text = [NSString stringWithFormat:@"%.8f",_location.coordinate.latitude];
self.longitudeLabel.text = [NSString stringWithFormat:@"%.8f",_location.coordinate.longitude];
self.tagButton.hidden = NO;
self.messageLabel.text = @"Here are your coordinates";
}
else {
self.latitudeLabel.text= @"";
self.longitudeLabel.text= @"";
self.adressLabel.text= @"";
self.tagButton.hidden = YES;
NSString *statusMessage;
if (_lastLocationError != nil) {
if ([_lastLocationError.domain isEqualToString:kCLErrorDomain] && _lastLocationError.code == kCLErrorDenied) {
statusMessage = @"Location Services Disabled";
} else {
statusMessage = @"Error getting location";
}
} else if (![CLLocationManager locationServicesEnabled]) {
statusMessage = @"Location Services Disabled";
} else if (_updatingLocation) {
statusMessage = @"Searching...";
} else {
statusMessage = @"Press the Button to start";
}
self.messageLabel.text = statusMessage;
}
}
- (void) startLocationManager
{
if ([CLLocationManager locationServicesEnabled]) {
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[_locationManager startUpdatingLocation];
_updatingLocation = YES;
}
}
- (void) stopLocationManager
{
if (_updatingLocation) {
[_locationManager stopUpdatingLocation];
_locationManager.delegate = nil;
_updatingLocation = NO;
}
}
@end
@end