簡體   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