MapView位置不工作(xcode 6中的ios7,sdk ios8)



我安装了developer.apple版本的XCODE 6(我认为是最后一个),我在那里工作我的项目(iOS 7项目),但显然带来了iOS 8 SDK,我真的不知道这是否会影响项目。

我有一个地图视图,我想显示用户的位置,但这是不可能的!代码:

@property (nonatomic, strong) CLLocationManager *manager;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.manager requestAlwaysAuthorization];
    [self.manager requestWhenInUseAuthorization];
    [self.mapview setDelegate:self];
    self.mapview.showsUserLocation = YES;

    [self.mapview setCenterCoordinate:self.mapview.userLocation.location.coordinate animated:YES];
}

我不知道"应用程序会使用你当前的位置…",地图视图显示了非洲的某个地方,没有别针或任何东西。

您必须初始化/分配CLLocationManager *manager

像这样的东西:

    // Create the core location manager object
        _locationManager = [[CLLocationManager alloc] init];
        self.locationManager.delegate = self;

    // for iOS 8, specific user level permission is required,
    // "when-in-use" authorization grants access to the user's location
    //
    // important: be sure to include NSLocationWhenInUseUsageDescription along with its
    // explanation string in your Info.plist or startUpdatingLocation will not work.
    //
    if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
        [self.locationManager requestWhenInUseAuthorization];
    }
    [self.locationManager startUpdatingLocation];

查看Apple示例https://developer.apple.com/library/prerelease/ios/samplecode/LocateMe/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007801

最新更新