我无法更新位置IOS

时间:2013-09-04 17:09:10

标签: ios xcode4.2 uialertview cllocationmanager

我正在尝试获取我所在位置的城市名称,我使用此代码:

- (void)viewDidLoad
{

    [super viewDidLoad];    CLLocationManager *locationManager =[[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    [locationManager startUpdatingLocation];


    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
     // Dispose of any resources that can be recreated.
}

//implementamos los metodos delegados de CLLocationManager.


- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation        *)newLocation fromLocation:(CLLocation *)oldLocation
{
    // this creates a MKReverseGeocoder to find a placemark using the found coordinates

    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError     *error) {
        NSString * location = ([placemarks count] > 0) ? [[placemarks objectAtIndex:0] locality] : @"Not Found";
        _ciudadLabel.text=location;


    }];
}


// this delegate method is called if an error occurs in locating your current location
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    NSLog(@"locationManager:%@ didFailWithError:%@", manager, error);
}

但是当我执行应用程序时,如果我想允许我的位置突然消失并且不执行该消息:

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    // this creates a MKReverseGeocoder to find a placemark using the found coordinates

    CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
    [geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
        NSString * location = ([placemarks count] > 0) ? [[placemarks objectAtIndex:0] locality] :   @"Not Found";
        _ciudadLabel.text=location;


    }];
}

为什么地点没有开始?

由于

0 个答案:

没有答案