locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
CLLocationDegrees latitude =locationManager.location.coordinate.latitude;
NSLog(@"纬度latitude--%f",latitude);
CLLocationDegrees longitude =locationManager.location.coordinate.longitude;
NSLog(@"经度 --%f",longitude);
myLocation.latitude = latitude;
myLocation.longitude = longitude;
[self showWithlocation:myLocation];
- (void) showWithlocation:(CLLocationCoordinate2D)location
{
Geocoder = [[CLGeocoder alloc] init];
CLGeocodeCompletionHandler handler = ^(NSArray *place, NSError *error){
for (CLPlacemark *placeMark in place) {
NSLog(@"%@",[placeMark.addressDictionary description] );
NSString *cityStr = [placeMark.addressDictionary objectForKey:@"City"];
NSLog(@"city %@",cityStr);
NSString *street = [placeMark.addressDictionary objectForKey:@"Street"];
NSLog(@"street %@",street);
NSString *state = [placeMark.addressDictionary objectForKey:@"State"];
NSLog(@"state %@",state);
NSString *zip = [placeMark.addressDictionary objectForKey:@"Zip"];
NSLog(@"zip %@",zip);
NSString *country = [placeMark.addressDictionary objectForKey:@"Country"];
NSLog(@"country %@",country);
NSString *countryCode = [placeMark.addressDictionary objectForKey:@"CountryCode"];
NSLog(@"countryCode %@",countryCode);
break;
}
};
CLLocation *loc = [[CLLocation alloc] initWithLatitude:location.latitude longitude:location.longitude];
[Geocoder reverseGeocodeLocation:loc completionHandler:handler];
}