MapView位置不起作用(xos 6中的ios7,sdk ios8)?

时间:2014-09-11 01:34:18

标签: ios xcode

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

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

@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];
}

我没有让应用程序使用您当前的位置...",mapview显示非洲的某个地方没有别针或任何东西。

1 个答案:

答案 0 :(得分:0)

您必须初始化/分配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