Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @property (weak, nonatomic) IBOutlet UITextField *addressOutlet;
- @property (weak, nonatomic) IBOutlet UITextField *cityOutlet;
- @property (strong, nonatomic) CLLocation *selectedLocation;
- @property (strong, nonatomic) NSMutableDictionary *placeDictionary;
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- self.addressOutlet.delegate = self;
- self.cityOutlet.delegate = self;
- self.mapView.delegate = self;
- self.placeDictionary = [[NSMutableDictionary alloc] init];
- CLLocationCoordinate2D zoomLocation;
- zoomLocation.latitude = 40.740848;
- zoomLocation.longitude= -73.991134;
- MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 1609.344,1609.344);
- [self.mapView setRegion:viewRegion animated:YES];
- }
- - (void)updatePlaceDictionary {
- [self.placeDictionary setValue:self.addressOutlet.text forKey:@"Street"];
- [self.placeDictionary setValue:self.cityOutlet.text forKey:@"City"];
- }
- - (void)updateMaps {
- CLGeocoder *geocoder = [[CLGeocoder alloc] init];
- [geocoder geocodeAddressDictionary:self.placeDictionary completionHandler:^(NSArray *placemarks, NSError *error) {
- if([placemarks count]) {
- CLPlacemark *placemark = [placemarks objectAtIndex:0];
- CLLocation *location = placemark.location;
- CLLocationCoordinate2D coordinate = location.coordinate;
- [self.mapView setCenterCoordinate:coordinate animated:YES];
- } else {
- NSLog(@"error, geen adres gevonden");
- }
- }];
- }
- - (void)delayedReverseGeocodeLocation {
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- [self reverseGeocodeLocation];
- }
- - (void)reverseGeocodeLocation {
- CLGeocoder *geocoder = [[CLGeocoder alloc] init];
- [geocoder reverseGeocodeLocation:self.selectedLocation completionHandler:^(NSArray *placemarks, NSError *error) {
- if(placemarks.count){
- NSDictionary *dictionary = [[placemarks objectAtIndex:0] addressDictionary];
- [self.addressOutlet setText:[dictionary valueForKey:@"Street"]];
- [self.cityOutlet setText:[dictionary valueForKey:@"City"]];
- }
- }];
- }
- - (IBAction)submitTapped:(id)sender {
- [self updatePlaceDictionary];
- [self updateMaps];
- }
- self.cityOutlet.text = @"Amsterdam";
- self.cityOutlet.hidden = YES;
- //[self.cityOutlet setText:[dictionary valueForKey:@"City"]];
- @property (nonatomic, strong) NSString* cityName;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement