Created
November 27, 2012 22:51
-
-
Save ChrisRisner/4157744 to your computer and use it in GitHub Desktop.
ios day 19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "CoreLocation/CoreLocation.h" | |
@protocol CoreLocationControllerDelegate | |
@required | |
- (void)update:(CLLocation *)location; | |
- (void)locationError:(NSError *)error; | |
@end | |
@interface CoreLocationController : NSObject <CLLocationManagerDelegate> | |
@property (nonatomic, retain) CLLocationManager *locationManager; | |
@property (nonatomic, retain) id delegate; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "CoreLocationController.h" | |
#import "CoreLocation/CoreLocation.h" | |
@implementation CoreLocationController | |
- (id)init { | |
self = [super init]; | |
if(self != nil) { | |
self.locationManager = [[CLLocationManager alloc] init]; | |
self.locationManager.delegate = self; | |
} | |
return self; | |
} | |
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { | |
[self.delegate update:newLocation]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { | |
[self.delegate locationError:error]; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <MapKit/MapKit.h> | |
#import "CoreLocationController.h" | |
@interface ViewController : UIViewController <CoreLocationControllerDelegate> | |
@property (weak, nonatomic) IBOutlet UILabel *lblLongitude; | |
@property (weak, nonatomic) IBOutlet UILabel *lblLatitude; | |
@property (weak, nonatomic) IBOutlet MKMapView *mapView; | |
@property (nonatomic, retain) CoreLocationController *locationController; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <MapKit/MapKit.h> | |
@interface ViewController : UIViewController | |
@property (weak, nonatomic) IBOutlet UILabel *lblLongitude; | |
@property (weak, nonatomic) IBOutlet UILabel *lblLatitude; | |
@property (weak, nonatomic) IBOutlet MKMapView *mapView; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
self.mapView.showsUserLocation = YES; | |
self.locationController = [[CoreLocationController alloc] init]; | |
self.locationController.delegate = self; | |
[self.locationController.locationManager startUpdatingLocation]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)update:(CLLocation *)location { | |
self.lblLatitude.text= [NSString stringWithFormat:@"Latitude: %f", [location coordinate].latitude]; | |
self.lblLongitude.text = [NSString stringWithFormat:@"Longitude: %f", [location coordinate].longitude]; | |
} | |
- (void)locationError:(NSError *)error { | |
self.lblLatitude.text = [error description]; | |
self.lblLongitude.text = nil; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
self.mapView.showsUserLocation = YES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment