Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. @property (weak, nonatomic) IBOutlet UITextField *addressOutlet;
  2. @property (weak, nonatomic) IBOutlet UITextField *cityOutlet;
  3.  
  4. @property (strong, nonatomic) CLLocation *selectedLocation;
  5. @property (strong, nonatomic) NSMutableDictionary *placeDictionary;
  6.  
  7. - (void)viewDidLoad
  8. {
  9. [super viewDidLoad];
  10.  
  11. self.addressOutlet.delegate = self;
  12. self.cityOutlet.delegate = self;
  13. self.mapView.delegate = self;
  14.  
  15. self.placeDictionary = [[NSMutableDictionary alloc] init];
  16. CLLocationCoordinate2D zoomLocation;
  17. zoomLocation.latitude = 40.740848;
  18. zoomLocation.longitude= -73.991134;
  19. MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1609.344,1609.344);
  20. [self.mapView setRegion:viewRegion animated:YES];
  21.  
  22. }
  23.  
  24. - (void)updatePlaceDictionary {
  25.  
  26. [self.placeDictionary setValue:self.addressOutlet.text forKey:@"Street"];
  27. [self.placeDictionary setValue:self.cityOutlet.text forKey:@"City"];
  28. }
  29.  
  30. - (void)updateMaps {
  31.  
  32. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  33. [geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
  34. if([placemarks count]) {
  35. CLPlacemark *placemark = [placemarks objectAtIndex:0];
  36. CLLocation *location = placemark.location;
  37. CLLocationCoordinate2D coordinate = location.coordinate;
  38. [self.mapView setCenterCoordinate:coordinate animated:YES];
  39. } else {
  40. NSLog(@"error, geen adres gevonden");
  41. }
  42. }];
  43.  
  44. }
  45.  
  46. - (void)delayedReverseGeocodeLocation {
  47.  
  48. [NSObject cancelPreviousPerformRequestsWithTarget:self];
  49.  
  50. [self reverseGeocodeLocation];
  51. }
  52.  
  53. - (void)reverseGeocodeLocation {
  54.  
  55. CLGeocoder *geocoder = [[CLGeocoder alloc] init];
  56. [geocoder reverseGeocodeLocation:self.selectedLocation completionHandler:^(NSArray *placemarks, NSError *error) {
  57.  
  58. if(placemarks.count){
  59. NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary];
  60. [self.addressOutlet setText:[dictionary valueForKey:@"Street"]];
  61. [self.cityOutlet setText:[dictionary valueForKey:@"City"]];
  62. }
  63. }];
  64. }
  65.  
  66. - (IBAction)submitTapped:(id)sender {
  67. [self updatePlaceDictionary];
  68. [self updateMaps];
  69. }
  70.  
  71. self.cityOutlet.text = @"Amsterdam";
  72. self.cityOutlet.hidden = YES;
  73.  
  74. //[self.cityOutlet setText:[dictionary valueForKey:@"City"]];
  75.  
  76. @property (nonatomic, strong) NSString* cityName;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement