在iphone 6.1模拟器上获取位置的麻烦

时间:2014-09-17 05:36:56

标签: ios objective-c iphone xcode

我对目标C和Xcode很新。我试图找出我的iphone模拟器的位置,并在youtube上阅读了一个教程。以下是代码。

#import "MainClassViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface MainClassViewController () <CLLocationManagerDelegate>

@end

@implementation MainClassViewController
{
    CLLocationManager *manager;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    manager = [[CLLocationManager alloc]init];

}

- (IBAction)LocationButton:(id)sender 
{

    manager.delegate = self;
    manager.desiredAccuracy = kCLLocationAccuracyBest;

    [manager startUpdatingLocation];

}

#pragma mark CLLocationManagerDelegate Methods

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"didFailWithError: %@", error);
    UIAlertView *errorAlert = [[UIAlertView alloc]
                           initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

-(void) locationManager:(CLLocationManager *)manager didUpdateLocations:(CLLocation *)newLocation fromLocation: (CLLocation *) oldLocation {

    NSLog(@"Location: %@", newLocation);
    CLLocation *currentLocation = newLocation;

    if(currentLocation != nil){
        _Lattitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude];
        _Longitude.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude];
    }
}

@end

#import <UIKit/UIKit.h>

@interface MainClassViewController : UIViewController

- (IBAction)LocationButton:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *Lattitude;
@property (weak, nonatomic) IBOutlet UILabel *Longitude;


@end

我的问题是: 1.我不确定为什么标签没有按位置更新。 2.我想了解更多有关调试的信息。任何合适的资源。请记住,我不想学习所有有关调试的知识。只有基本要求。

0 个答案:

没有答案