Skip to content

Instantly share code, notes, and snippets.

@kristersj
Last active December 30, 2015 09:29
Show Gist options
  • Save kristersj/7809824 to your computer and use it in GitHub Desktop.
Save kristersj/7809824 to your computer and use it in GitHub Desktop.
Get current locations city name, country.
@interface AppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate>
@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