locationManager返回0.0000,错误在哪里?

时间:2013-08-28 21:37:33

标签: ios objective-c cllocationmanager xcode4.6.3

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

我已经设置了locationManager,并希望将浮动正确地转换为字符串,但是当我测试应用程序时它仍然显示为0.00000。

locationManager中有问题吗?或者这些信息是否以某种方式丢失了?我的代码在这里:

由于

    //
//  StartVC.m
//  Etterforskning
//
//  Created by Knut Gjærde on 8/28/13.
//  Copyright (c) 2013 Knut G. All rights reserved.
//

#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

1 个答案:

答案 0 :(得分:1)

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

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