Created
December 6, 2012 07:20
-
-
Save ryanhanwu/4222448 to your computer and use it in GitHub Desktop.
[iOS] Get current location and city name
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 myViewController: UIViewController <CLLocationManagerDelegate> | |
CLLocationManager *locationManager; | |
CLLocation *currentLocation; | |
@end |
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
@implementation AuthViewController | |
- (void)viewDidLoad | |
{ | |
locationManager = [CLLocationManager new]; | |
locationManager.delegate = self; | |
locationManager.distanceFilter = kCLDistanceFilterNone; | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest; | |
[locationManager startUpdatingLocation]; | |
} | |
#pragma mark CLLocationManager Delegate | |
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { | |
currentLocation = [locations objectAtIndex:0]; | |
[locationManager stopUpdatingLocation]; | |
NSLog(@"Detected Location : %f, %f", currentLocation.coordinate.latitude, currentLocation.coordinate.longitude); | |
CLGeocoder *geocoder = [[CLGeocoder alloc] init] ; | |
[geocoder reverseGeocodeLocation:currentLocation | |
completionHandler:^(NSArray *placemarks, NSError *error) { | |
if (error){ | |
NSLog(@"Geocode failed with error: %@", error); | |
return; | |
} | |
CLPlacemark *placemark = [placemarks objectAtIndex:0]; | |
NSLog(@"placemark.ISOcountryCode %@",placemark.ISOcountryCode); | |
}]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Get current city and country name in swift 3 or later