2012-03-23 21 views
1

私のサービスにはGPSが必要です。私は実際にGPSをオンにし、ロケーションが有効かどうかをチェックしてから、しばらくの間スリープ状態になるサービスを実装しました。 (5秒から始まり、動きが検出されない場合は1分ほど眠ることができます) その後、私は再びGPSを開始し、新しい場所を取得します。iOS GPSバッテリーの消耗を少なくする方法

しかし、バッテリーの残量はまだ高いです! IveはlocMgr.distanceFilter = 10.0fとdesiredAccurady = NearestTenMetersを使用しました。

バッテリの放電を最小限に抑えるにはどうすればよいですか?

答えて

1

これは私の扱いです。私は場所を取得した後、私はそれをNSDictionaryに格納します。その後、私は再び位置を取得する必要がある場合は、GPSをオンに戻す代わりにNSDictionaryを返します。 2分後、私はNSDictionaryをリセットします(最適なスイートになるまでの時間を調整できます)。その後、NSDictionaryがリセットされた後に次回に私はGPSから新しい場所を取得する必要があります。

- (NSDictionary *) getCurrentLocation { 

if (self.currentLocationDict == nil) { 
    self.currentLocationDict = [[NSMutableDictionary alloc] init]; 

    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    [locationManager startUpdatingLocation]; 

    CLLocation *myLocation = [locationManager location]; 

    [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.latitude] forKey:@"lat"]; 
    [self.currentLocationDict setObject:[NSString stringWithFormat:@"%f", myLocation.coordinate.longitude] forKey:@"lng"]; 
    [locationManager stopUpdatingLocation]; 
    [locationManager release]; 

    //Below timer is to help save battery by only getting new location only after 2 min has passed from the last time a new position was taken. Last location is saved in currentLocationDict 
    [NSTimer scheduledTimerWithTimeInterval:120 target:self selector:@selector(resetCurrentLocation) userInfo:nil repeats:NO]; 
} 

return self.currentLocationDict; 
} 

- (void) resetCurrentLocation { 
NSLog(@"reset"); 
[currentLocationDict release]; 
self.currentLocationDict = nil; 
} 
+0

これは私が欲しかったものではありません。バッテリーの消耗についてより多くの洞察が必要です。 –

関連する問題