【发布时间】:2014-09-03 05:58:18
【问题描述】:
我正在使用 Obj-C NOT SWIFT 在 iOS 8 中使用 Map Kit。我无法获取设置为 0.00、0.00 的设备位置,并且出现错误:
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我已经实现了:(我一次只尝试了一个,没有运气)
if(IS_OS_8_OR_LATER) {
[self.locationManager requestWhenInUseAuthorization];
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
在 info.plist 中
NSLocationWhenInUseUsageDescription : App would like to use your location.
NSLocationAlwaysUsageDescription : App would like to use your location.
确实会提示我允许该应用使用我的位置,但在我同意之后没有任何更改。位置显示为 0.00, 0.00。
显示用户位置的代码:
//Get Location
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
MKCoordinateRegion region = { { 0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = self.locationManager.location.coordinate.latitude;
region.center.longitude = self.locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.005f;
region.span.longitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];
迈克。
**编辑:查看下面的答案。
【问题讨论】:
-
我也无法让 cl 正常工作。有了这个测试版(感觉是 alpha),如果它在 ios7 上运行,我认为你不应该受到责备
-
第 N 次:您不应期望 locationManager.location 在调用 startUpdatingLocation 后立即始终具有有效值。您必须实现 didUpdateLocations 委托方法并在那里处理位置。不要忘记将 locationManager.delegate 设置为 self ,否则不会调用委托方法。
标签: objective-c mapkit cllocationmanager ios8