- Integrating GPS to my application
- #import "MyCLController.h"
- @interface HelloThereViewController : UIViewController <MyCLControllerDelegate> {
- MyCLController *locationController;
- }
- - (void)locationUpdate:(CLLocation *)location;
- - (void)locationError:(NSError *)error;
- @end
- #import "HelloThereViewController.h"
- @implementation HelloThereViewController
- - (void)viewDidLoad {
- locationController = [[MyCLController alloc] init];
- locationController.delegate = self;
- [locationController.locationManager startUpdatingLocation];
- //I need to print the latitude and logitude values here..
- }
- @protocol MyCLControllerDelegate
- @required
- - (void)locationUpdate:(CLLocation *)location;
- - (void)locationError:(NSError *)error;
- @end
- @interface MyCLController : NSObject {
- CLLocationManager *locationManager;
- id delegate;
- }
- @property (nonatomic, retain) CLLocationManager *locationManager;
- @property (nonatomic, assign) id delegate;
- - (void)locationManager:(CLLocationManager *)manager
- didUpdateToLocation:(CLLocation *)newLocation
- fromLocation:(CLLocation *)oldLocation;
- - (void)locationManager:(CLLocationManager *)manager
- didFailWithError:(NSError *)error;
- @end
- #import "MyCLController.h"
- @implementation MyCLController
- @synthesize locationManager;
- @synthesize delegate;
- - (id) init {
- self = [super init];
- if (self != nil) {
- self.locationManager = [[[CLLocationManager alloc] init] autorelease];
- self.locationManager.delegate = self;
- }
- return self;
- }
- - (void)locationManager:(CLLocationManager *)manager
- didUpdateToLocation:(CLLocation *)newLocation
- fromLocation:(CLLocation *)oldLocation
- {
- [self.delegate locationUpdate:newLocation];
- }
- - (void)locationManager:(CLLocationManager *)manager
- didFailWithError:(NSError *)error
- {
- [self.delegate locationError:error];
- }
- - (void)dealloc {
- [self.locationManager release];
- [super dealloc];
- }
- @end