我正在使用iOS8 [8.0.2]
,无论我尝试什么,我都无法让CLLocationManager
工作。
我在info.plist
添加了以下几行。
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app use location services.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This app use location services.</string>
在我的实施文件中:
In ViewDidLoad :
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager requestAlwaysAuthorization];
[locationManager startUpdatingLocation];
但是没有调用以下方法。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
我错过了什么?
答案 0 :(得分:0)
选中post。
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
上述代理在iOS 6中已弃用。请改用以下代码:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
修改强>
在通过mapView.showUserLocation
locationManager:didUpdateLocations:
设置为YES
这样设置:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
self.mapView.showUserLocation = YES;
[locationManager stopUpdatingLocation];
}
答案 1 :(得分:0)