简体   繁体   English

Objective-C-核心位置-iOS 7.1

[英]Objective-C - Core Location - iOS 7.1

I have a code in a UIViewController that starts the location update: [locationManager startUpdatingLocation]; 我在UIViewController中有一个代码,用于开始位置更新: [locationManager startUpdatingLocation];

Is working perfectly. 运行良好。 But I need every time you exit this screen it stops updating the location and start again when I return. 但是,我需要每次退出此屏幕时都停止更新位置,并在我返回时重新开始。

The first time it for updates. 第一次进行更新。 In other times it does not stop. 在其他时候,它不会停止。

Code for exit from view: 从视图退出的代码:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

Ihave tried also: (without success too) 我也尝试过:(也没有成功)

[locationManager stopMonitoringSignificantLocationChanges];
[locationManager stopUpdatingHeading];
[locationManager stopUpdatingLocation];

locationManager.delegate = nil;
locationManager = nil;

It always update. 它总是更新。 But from the second time not stop update. 但是从第二次开始就不停止更新。

didUpdateLocation code: didUpdateLocation代码:

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ [self addingMarkerUser]; }

You should put your code in the viewDidAppear and i suppose in your [self addingMarkerUser] you use something like this without the stop (if not, please provide the code) : 您应该将代码放入viewDidAppear并且我想在您的[self addingMarkerUser]使用类似的内容(如果没有,请提供代码):

CLGeocoder *geocoder = [[CLGeocoder alloc] init] ;
    [geocoder reverseGeocodeLocation:_currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {

 if (!(error)) {
              //do something with the data.
              //then stop the update.
            [locationManager stopUpdatingLocation];

        }
    }];

If you do like that, every time your view appear, the location will start the update then stop once the data retrieve. 如果您这样做的话,每当您的视图出现时,该位置将开始更新,然后在数据检索后停止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM