我正在编写一个应用程序,除其他外,它具有显示地址和用户所在位置的经度/纬度的功能。
我已经设置了 locationManager,并希望将浮点数正确转换为字符串,但是当我测试应用程序时,它仍然显示为 0.00000。
问题出在 locationManager 中吗?或者信息是否以某种方式丢失了?我在这里有我的代码:
谢谢
//
// StartVC.m
//
#import "StartVC.h"
@interface StartVC () {
/* IBOutlet UILabel * _Gatenavn;
IBOutlet UILabel * _Gatenr;
IBOutlet UILabel * _Postnr;
IBOutlet UILabel * _Poststed; */
IBOutlet UILabel * _Lengdegrad;
IBOutlet UILabel * _Breddegrad;
float Breddegrad;
float Lengdegrad;
}
@property (assign, nonatomic) CLLocationDistance distanceFilter;
@property(assign, nonatomic) CLLocationAccuracy desiredAccuracy;
@end
@implementation StartVC
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
_Breddegrad.text = [NSString stringWithFormat:@"%1.6f", Breddegrad];
_Lengdegrad.text = [NSString stringWithFormat:@"%1.6f", Lengdegrad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)startSignificantChangeUpdates
{
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
if (nil == locationManager)
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
// If it's a relatively recent event, turn off updates to save power
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 15.0) {
// If the event is recent, do something with it.
Breddegrad = location.coordinate.latitude;
Lengdegrad = location.coordinate.longitude;
}
}
@end