Last active
December 30, 2015 09:29
-
-
Save kristersj/7809824 to your computer and use it in GitHub Desktop.
Get current locations city name, country.
This file contains 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
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate> |
This file contains 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
@synthesize locationManager; | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
//.............VIEW SETUP CODE................ | |
//Current city | |
locationManager = [CLLocationManager new]; | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest; | |
locationManager.delegate = self; | |
[locationManager startUpdatingLocation]; | |
} | |
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations | |
{ | |
CLLocation *currentLocation = [locations objectAtIndex:0]; | |
[locationManager stopUpdatingLocation]; | |
CLGeocoder *coder = [[CLGeocoder alloc] init]; | |
[coder reverseGeocodeLocation:currentLocation completionHandler: ^(NSArray *placemarks, NSError *error) { | |
CLPlacemark *placemark = [placemarks objectAtIndex:0]; | |
NSLog(@"Current location: %@, %@", placemark.locality, placemark.country); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment