//
//  Converting_Longitude_and_Latitude_to_a_Meaningful_AddressViewController.m
//  Converting Longitude and Latitude to a Meaningful Address
//
//  Created by Vandad Nahavandipoor on 15/07/2011.
//  Copyright 2011 Pixolity Ltd. All rights reserved.
//

#import "Converting_Longitude_and_Latitude_to_a_Meaningful_AddressViewController.h"

@implementation
  Converting_Longitude_and_Latitude_to_a_Meaningful_AddressViewController

@synthesize myGeocoder;

- (void)didReceiveMemoryWarning{
  [super didReceiveMemoryWarning];
}

- (void)viewDidLoad{
  [super viewDidLoad];
  
    CLLocation *location = [[CLLocation alloc] initWithLatitude:50.288865
                                                      longitude:18.662042];


  self.myGeocoder = [[CLGeocoder alloc] init];
  
  [self.myGeocoder
   reverseGeocodeLocation:location
   completionHandler:^(NSArray *placemarks, NSError *error) {
     
     if (error == nil &&
         [placemarks count] > 0){
       
       CLPlacemark *placemark = [placemarks objectAtIndex:0];
       /* Otrzymaliśmy wyniki */
       NSLog(@"Kraj = %@", placemark.country);
       NSLog(@"Kod pocztowy = %@", placemark.postalCode);
       NSLog(@"Miejscowość = %@", placemark.locality);
     }
     else if (error == nil &&
              [placemarks count] == 0){
       NSLog(@"Nie znaleziono żadnych wyników.");
     }
     else if (error != nil){
       NSLog(@"Wystąpił błąd = %@", error);
     }
     
   }];
}

- (void)viewDidUnload{
  [super viewDidUnload];
  self.myGeocoder = nil;
}


- (BOOL)shouldAutorotateToInterfaceOrientation
        :(UIInterfaceOrientation)interfaceOrientation{
  return YES;
}

@end
