我仍然是xcode的初学者和整个目标-C。
我正在创建一个应用程序,您可以在屏幕上看到您的坐标(它仍处于开始阶段)
但是用户无法看到坐标的准确程度......我可以在调试区看到,但使用该应用程序的用户无法看到它。
如何在我的代码中添加?
我的代码目前是:
#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;
}
- (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
答案 0 :(得分:0)
horizontalAccuracy
是CLLocation的属性。它以米为单位报告当前的水平精度。这意味着您的真实位置距离报告的任何方向位置都要horizontalAccuracy
米
参考您的updateLabels
代码,您可以访问_location.horizontalAccuracy
并将其与其他信息一起显示
有一个类似的属性verticalAccuracy
。