Created
December 6, 2016 11:11
-
-
Save IvanovDeveloper/cf754eb6661835690868c8e1a6b63435 to your computer and use it in GitHub Desktop.
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 <CoreLocation/CoreLocation.h> | |
@interface LocationManager () <CLLocationManagerDelegate> | |
@property (nonatomic, strong) CLLocationManager *locationManager; | |
@end | |
@implementation | |
- (id)init | |
self = [super init]; | |
if (self) { | |
[self startLocationManager]; | |
} | |
return self; | |
} | |
- (void)startLocationManager { | |
locationManager = [[CLLocationManager alloc] init]; | |
locationManager.delegate = self; | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest; | |
[locationManager startUpdatingLocation]; | |
} | |
#pragma mark - CLLocationManagerDelegate | |
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation | |
{ | |
NSLog(@"didUpdateToLocation: %@", newLocation); | |
CLLocation *currentLocation = newLocation; | |
if (currentLocation != nil) { | |
longitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.longitude]; | |
latitudeLabel.text = [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; | |
} | |
} | |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { | |
NSLog(@"didFailWithError: %@", error); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment