I am trying to get the Map Kit to display the current user's location down to a predefined size.
Everything was working but since updating to Xcode 6 and iOS 8, things have changed.
I have implemented the necessary authorizations and now the app crashes. The code with ***
is the code that the system seems to have a problem with.
Here is Map.m
#import "MRVCMapViewController.h"
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
@import CoreLocation;
@interface MRVCMapViewController ()
@end
@implementation MRVCMapViewController
@synthesize mapView;
- (void)viewDidLoad {
[super viewDidLoad];
//location permission
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];
//mapview settings
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;
}
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
***MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];***
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
You haven't checked that the
userLocation
value is valid. You should make sure it is notnil
before trying to use it for anything.