繁体   English   中英

Objective-C-核心位置-iOS 7.1

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

我在UIViewController中有一个代码,用于开始位置更新: [locationManager startUpdatingLocation];

运行良好。 但是,我需要每次退出此屏幕时都停止更新位置,并在我返回时重新开始。

第一次进行更新。 在其他时候,它不会停止。

从视图退出的代码:

[locationManager stopUpdatingLocation];
locationManager.delegate = nil;

我也尝试过:(也没有成功)

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

locationManager.delegate = nil;
locationManager = nil;

它总是更新。 但是从第二次开始就不停止更新。

didUpdateLocation代码:

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

您应该将代码放入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];

        }
    }];

如果您这样做的话,每当您的视图出现时,该位置将开始更新,然后在数据检索后停止。

暂无
暂无

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

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