gpt4 book ai didi

ios - locationManager返回0.0000,错误在哪里?

转载 作者:行者123 更新时间:2023-11-29 03:40:46 25 4
gpt4 key购买 nike

我正在编写一个应用程序,除其他外,它具有显示地址和用户所在位置的经度/纬度的功能。

我已经设置了 locationManager,并希望正确地将 float 转换为字符串,但是当我测试应用程序时,它仍然显示为 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

最佳答案

您没有更新标签。您应该将以下内容移至另一个方法并在 locationManager:didUpdateLocations: 中调用它。

_Breddegrad.text = [NSString stringWithFormat:@"%1.6f", Breddegrad];
_Lengdegrad.text = [NSString stringWithFormat:@"%1.6f", Lengdegrad];

关于ios - locationManager返回0.0000,错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18498664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com