Friday, July 9, 2010

Location Manager Delegate methods.....

-(IBAction)btn_Clicked:(id)sender
{
if(locationManager.locationServicesEnabled)
{
[spinner startAnimating];
btn.enabled = NO;
[locationManager startUpdatingLocation];
}
}

#pragma mark -
#pragma mark Geo Points methods

//It will be called whenever the device is able to detect GPS locations.....

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
if(newLocation != nil)
appDelegate.currentLocation = newLocation;
else
appDelegate.currentLocation = oldLocation;

[locationManager stopUpdatingLocation];
btn.enabled = YES;
[spinner stopAnimating];

UIMyViewController *myViewController = [[UIMyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self.navigationController pushViewController:myViewController animated:YES];
[stateViewController release];
}


//It will be called when device will fail to get GPS location and will show a popup with "Don't Allow" and "Ok" button.....

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
[locationManager stopUpdatingLocation];
btn.enabled = YES;
[spinner stopAnimating];

UIMyViewController *myViewController = [[UIMyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self.navigationController pushViewController:myViewController animated:YES];
[stateViewController release];

/*if (error.code == kCLErrorDenied)
{
// User denied access to location service
printf("\n\n Don't Allow Clicked.");
}
else if (error.code == kCLErrorLocationUnknown)
{
// User denied access to location service
printf("\n\n OK Clicked.");
}
else if (error.code == kCLErrorNetwork)
{
// User denied access to location service
printf("\n\nmy error kCLErrorNetwork.");
}
else if (error.code == kCLErrorHeadingFailure)
{
// User denied access to location service
printf("\n\nmy error kCLErrorHeadingFailure.");
}*/
}

1 comment:

  1. code is very usefull but
    pls put download preview code..

    ReplyDelete