Working on application that needs to update current location in every second.
for that i am using CoreLocation
framework.
My code is like
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];
}
and implementing it's Delegate methods
-(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]);
}
My Problem is that when i am running this code into simulator then it's working fine and updating location every second but when i run it into device then it shows location updating 3 or 4 times only.
I need this code working in both iphone 4 & iphone 5.
I have not found any solution for that.
Actually i need to count distance or count steps..for that i can also accelerometer but it's not giving perfect solution.
Please Help...
Thanks !