2012-10-27 50 views
0

在我的應用程序中,我實現了Cllocation管理器以使用當前用戶位置&,它工作正常。但是當應用程序在後臺輸入或終止時,GPS位置圖標會自動隱藏在iPod中。當我嘗試與iPhone相同時,圖標不會隱藏。Gps位置圖標未關閉

所以,我找不到任何解決方案。幫我!!

我的代碼如下:

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
    { 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

if(locationManager == nil) 

     locationManager =[[CLLocationManager alloc] init]; 

    self.locationManager.delegate = self; 

    self.locationManager.desiredAccuracy= kCLLocationAccuracyBest; 

    self.locationManager.distanceFilter= 5; 

    [locationManager startUpdatingLocation]; 
    [locationManager startUpdatingHeading]; 
} 


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

    self.userLocation=newLocation; 

    [self.locationManager startMonitoringSignificantLocationChanges]; 
} 

Map.m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [APPDELEGATE.locationManager startUpdatingLocation]; 

} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    self.map.delegate = self; 

    [self.map setShowsUserLocation:YES]; 
} 

如果我手動對我的iPod應用程序的位置服務,當應用程序是關閉,它沒有顯示位置圖標。但是,當我嘗試在iPhone中相同,它顯示位置圖標。

回答

0

我想你真正想要的是:

[self.locationManager stopUpdatingLocation]; 

直接以後,如果你想法力GER醒來在顯著的位置變化,然後調用:

[self.locationManager startMonitoringSignificantLocationChanges]; 

相反適用回到不斷更新:

[self.locationManager stopMonitoringSignificantLocationchanges]; 
[self.locationManager startUpdatingLocation]; 

注:在顯着位置更改模式,在狀態的圖標當連續更新位置時,條仍然會顯示相同。這不是一個需要關注的問題,因爲在保守模式下,它在不需要時仍然關閉位置服務。
該ipod不支持startMonitoringSignificantLocationChanges。這就是爲什麼該指標在兩臺設備上表現不同。

您應該考慮到,正如您已經實施的那樣,您正在使用任何第一個事件報告來查找經理的位置。這通常可能是陳舊的,緩存的,舊的或很可能非常不準確的。這是標準做法,使用一點測試,併爲您的目的提供一個更合適的位置信息所需的機會。

請在Github上查看my handler以獲得更多幫助,因爲您可以使用位置服務。

1

終於我解決了這個問題,如下所示。

而不是

[self.locationManager startMonitoringSignificantLocationChanges]; 

在的appdelegate

我寫,

[self.locationManager stopMonitoringSignificantLocationChanges];