IOS 7 - region.center deprecated

I have this code for my iOS application:

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 was deprecated. Is there a replacement I should use? Is this even the right way to create a map in a view?

Thanks!!

+7
ios ios7 maps
source share
3 answers

Try the following:

 region.center = [(CLCircularRegion *)placemark.region center]; 
+21
source share

if you just want to get the center of the region that you can use:

region.center = placemark.location.coordinate

+8
source share

A combination of Heesien and other answers and a bit of experimentation.

 - (void)centerMapAroundPlacemark:(MKPlacemark *)placemark { CLRegion *region = placemark.region; if ([region isKindOfClass:[CLCircularRegion class]]) { [self centerMapAroundCircularRegion:(CLCircularRegion *)region centerCoodinate:placemark.location.coordinate]; } else { [self centerMapAroundCoorinate:placemark.location.coordinate]; } } - (void)centerMapAroundCircularRegion:(CLCircularRegion *)circularRegion { MKCoordinateRegion coordinateRegion = MKCoordinateRegionMakeWithDistance(circularRegion.center, circularRegion.radius, circularRegion.radius); [self.mapView setRegion:coordinateRegion animated:YES]; } - (void)centerMapAroundCircularRegion:(CLCircularRegion *)circularRegion centerCoodinate:(CLLocationCoordinate2D)centerCoodinate { // Only user the radius of region for an appropriate zoom level. // The center of the region is not accurate. // To see this search for 'Bath, UK' MKCoordinateRegion coordinateRegion = MKCoordinateRegionMakeWithDistance(centerCoodinate, circularRegion.radius, circularRegion.radius); [self.mapView setRegion:coordinateRegion animated:YES]; } 
0
source share

All Articles