I’m trying to zoom a map into the user’s current location once the view loads, but I’m getting the error “** * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Invalid Region ‘” when the view loads. Please can someone help?
Cheers!
- (void)viewDidLoad
{
[super viewDidLoad];
MKCoordinateRegion mapRegion;
mapRegion.center.latitude = map.userLocation.coordinate.latitude;
mapRegion.center.longitude = map.userLocation.coordinate.longitude;
mapRegion.span.latitudeDelta = 0.2;
mapRegion.span.longitudeDelta = 0.2;
[map setRegion:mapRegion animated: YES];
}
did you set
showsUserLocation = YES?MKMapViewwon’t update the location if it is set toNO. So make sure of that.It is very likely that the
MKMapViewobject doesn’t have the user location yet. To do right, you should adoptMKMapViewDelegateprotocol and implementmapView:didUpdateUserLocation: