one more bad day god knows whats the problem with this but delegate methods for CLLocation Mangaer are not called once I click a refresh button, on click of this button I ask location manager to update location
-(void) viewWillAppear:(BOOL)animated{
locationManager=[[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
NSLog(@"failed");
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(@"current lat= %f and long=%f ", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
NSDate *eventDate = newLocation.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (abs(howRecent) < 10) {
[lat setText:[ NSString stringWithFormat:@"%f", newLocation.coordinate.latitude]];
[lon setText:[ NSString stringWithFormat:@"%f", newLocation.coordinate.longitude]];
}
else {
[lat setText:@"Not changed"];
[lon setText:@"Not changed"];
}
}
-(IBAction) refrechLoc{
NSLog(@"updating location");
[locationManager startUpdatingLocation];
}
Please help me resolve this issue.
Thanks in advance
It seems that it is beginning updating on
viewWillAppear, so it won’t update the location until it is not stopped bystopUpdatingLocation. If you want to restart updating you should callstopUpdatingLocationbeforestartUpdatingLocation:imho, there is no need in location updating restart in general