简体   繁体   English

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

[英]MapView location not working (ios7 in xcode 6, sdk ios8)?

I installed XCODE 6 the version form developer.apple (I think is the final one) and Im working my projects there (iOS 7 projects) but obviously brings iOS 8 SDK I really don't know if this affects the project. 我安装了XCODE 6版本的形式为developer.apple(我认为是最终版本),我在那里在那里工作我的项目(iOS 7项目),但显然带来了iOS 8 SDK,我真的不知道这是否会影响项目。

I have a mapview and I want to show the user location but it's impossible! 我有一个mapview,我想显示用户位置,但这是不可能的! Code: 码:

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

I don't get the "App whants to use your current location...", The mapview shows some place in Africa without pin or anything. 我没有看到“ App想使用您的当前位置...”,该地图视图显示了非洲的一些地方,没有图钉或其他任何东西。

You must init/alloc the CLLocationManager *manager 您必须初始化/分配CLLocationManager *manager

something like this: 像这样的东西:

    // 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];

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM