Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 - region.center deprecated

Tags:

ios

ios7

maps

I have this code for my iOS app:

NSString *location = [[NSString alloc] initWithFormat:@"%@, %@", [self.campus campusStreetAddress], [self.campus campusCityStateZip]];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
             completionHandler:^(NSArray* placemarks, NSError* error){
                 if (placemarks && placemarks.count > 0) {
                     CLPlacemark *topResult = [placemarks objectAtIndex:0];
                     MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
                     MKCoordinateRegion region = self.campusMap.region;
                     region.center = placemark.region.center; //DEPRECATED iOS 7
                     region.span.longitudeDelta /= 1500;
                     region.span.latitudeDelta /= 1500;
                     [self.campusMap setRegion:region animated:NO];
                     [self.campusMap addAnnotation:placemark];
                 }
             }
 ];

But, when I upgraded my app to iOS 7, placemark.region.center is deprecated. Is there a replacement I should use? Is this even a proper method to creating a map in a view?

Thanks!!

like image 483
jordangrogan Avatar asked Oct 04 '13 17:10

jordangrogan


2 Answers

Try this:

region.center = [(CLCircularRegion *)placemark.region center];
like image 148
Heesien Ooi Avatar answered Sep 22 '22 02:09

Heesien Ooi


if you just want the center of the region you can use :

region.center = placemark.location.coordinate

like image 38
Diego Avatar answered Sep 23 '22 02:09

Diego