毎秒現在の場所を更新する必要があるアプリケーションに取り組んでいます。
そのために私はCoreLocation
フレームワークを使用しています。
私のコードは
AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
{
}
@property (nonatomic, retain) CLLocationManager *locationManager;
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[locationManager startMonitoringSignificantLocationChanges];
[locationManager retain];
}
そしてそれのデリゲートメソッドを実装する
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CLLocation *locB = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.longitude];
NSLog(@"New location is >>>>>> %@",locB);
}
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@">>>>>>>>>> error :%@", [error description]);
}
私の問題は、このコードをシミュレーターに実行すると正常に動作し、毎秒位置を更新しますが、デバイスに実行すると位置の更新が 3 回または 4 回しか表示されないことです。
iPhone 4とiPhone 5の両方でこのコードが機能する必要があります。
私はそれに対する解決策を見つけていません。
実際には、距離を数えるか、歩数を数える必要があります..そのために、加速度計も使用できますが、完全な解決策にはなりません。
助けてください...
ありがとう !