0

我试图让 Map Kit 将当前用户的位置显示为预定义的大小。

一切正常,但自从更新到 Xcode 6 和 iOS 8 后,情况发生了变化。

我已经实施了必要的授权,现在应用程序崩溃了。带有***的代码是系统似乎有问题的代码。

这里是 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
4

1 回答 1

1

您尚未检查该userLocation值是否有效。nil在尝试将其用于任何事情之前,您应该确保它不是。

于 2014-09-21T20:12:23.500 回答