Skip to content

Instantly share code, notes, and snippets.

@frr149
Created February 23, 2012 11:43
Show Gist options
  • Save frr149/1892504 to your computer and use it in GitHub Desktop.
Save frr149/1892504 to your computer and use it in GitHub Desktop.
reverse geocoding with CoreLocation
-(void) addressFromLocation: (CLLocation *) aLocation{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
self.activity.hidden = NO;
[self.activity startAnimating];
self.output.text = @"Ahora lo averiguo. Contactando con Paco Lobatón...";
[geocoder reverseGeocodeLocation:aLocation
completionHandler:^(NSArray *placemarks, NSError *error) {
if (placemarks && placemarks.count > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.output.text = [NSString stringWithFormat:@"%@ %@, %@ %@",
[placemark subThoroughfare],
[placemark thoroughfare],
[placemark locality],
[placemark administrativeArea]];
self.background.image = [UIImage imageNamed:@"pacoLobaton.jpg"];
}else{
self.output.text = @"Estás perdido. Llama a Lobatón";
}
[self.activity stopAnimating];
NSLog(@"%@", self.output.text);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment