[英]MapView location not working (ios7 in xcode 6, sdk ios8)?
我安裝了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];
}
我沒有看到“ App想使用您的當前位置...”,該地圖視圖顯示了非洲的一些地方,沒有圖釘或其他任何東西。
您必須初始化/分配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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.