locationManager returning 0.0000, where is the error?

355 views Asked by At

I am writing an app that will, amongst others, have a function where it shows an address and the longditude/latitude where the user is.

I have set up the locationManager, and hopefully converted the floats into strings correctly, but when I test the app it still shows up as 0.00000.

Is the problem in the locationManager? or did the information somehow get lost underway? I have my code here:

Thanks

    //
//  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
1

There are 1 answers

3
fumoboy007 On

You are not updating your labels. You should move the following to another method and invoke it in locationManager:didUpdateLocations:.

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