Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.93 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Integrating GPS to my application
  2. #import "MyCLController.h"
  3.  
  4. @interface HelloThereViewController : UIViewController <MyCLControllerDelegate> {
  5.     MyCLController *locationController;
  6. }
  7.  
  8. - (void)locationUpdate:(CLLocation *)location;
  9. - (void)locationError:(NSError *)error;
  10.  
  11. @end
  12.        
  13. #import "HelloThereViewController.h"
  14.  
  15. @implementation HelloThereViewController
  16.  
  17. - (void)viewDidLoad {
  18.     locationController = [[MyCLController alloc] init];
  19.     locationController.delegate = self;
  20.     [locationController.locationManager startUpdatingLocation];
  21.  
  22.     //I need to print the latitude and logitude values here..
  23. }
  24.        
  25. @protocol MyCLControllerDelegate
  26. @required
  27. - (void)locationUpdate:(CLLocation *)location;
  28. - (void)locationError:(NSError *)error;
  29. @end
  30.  
  31. @interface MyCLController : NSObject  {
  32.     CLLocationManager *locationManager;
  33.     id delegate;
  34. }
  35.  
  36. @property (nonatomic, retain) CLLocationManager *locationManager;
  37. @property (nonatomic, assign) id  delegate;
  38.  
  39. - (void)locationManager:(CLLocationManager *)manager
  40.     didUpdateToLocation:(CLLocation *)newLocation
  41.            fromLocation:(CLLocation *)oldLocation;
  42.  
  43. - (void)locationManager:(CLLocationManager *)manager
  44.        didFailWithError:(NSError *)error;
  45.  
  46. @end
  47.        
  48. #import "MyCLController.h"
  49.  
  50. @implementation MyCLController
  51.  
  52. @synthesize locationManager;
  53. @synthesize delegate;
  54.  
  55. - (id) init {
  56.     self = [super init];
  57.     if (self != nil) {
  58.         self.locationManager = [[[CLLocationManager alloc] init] autorelease];
  59.         self.locationManager.delegate = self;
  60.     }
  61.     return self;
  62. }
  63.  
  64. - (void)locationManager:(CLLocationManager *)manager
  65.     didUpdateToLocation:(CLLocation *)newLocation
  66.          fromLocation:(CLLocation *)oldLocation
  67. {
  68.     [self.delegate locationUpdate:newLocation];
  69. }
  70.  
  71. - (void)locationManager:(CLLocationManager *)manager
  72.        didFailWithError:(NSError *)error
  73. {
  74.     [self.delegate locationError:error];
  75. }
  76.  
  77. - (void)dealloc {
  78.     [self.locationManager release];
  79.     [super dealloc];
  80. }
  81.  
  82. @end