如何在iOS 7中请求位置

时间:2016-05-26 06:52:34

标签: ios swift cllocationmanager

我想在iOS 7+中请求位置。我可以在iOS 8+中实现这一点:

locationManager.delegate = self 
locationManager.desiredAccuracy = kCLLocationAccuracyBest 
locationManager.requestWhenInUseAuthorization() 
locationManager.requestLocation()

但在iOS 7中,我无法使用这两行:

locationManager.requestWhenInUseAuthorization()
locationManager.requestLocation()

enter image description here

任何帮助将不胜感激。感谢。

1 个答案:

答案 0 :(得分:-2)

创建CLLocationManager的实例(最好在您的AppDelegate中)。强烈提及它。

-(void)startLocationService{

    self.locationManager = [[CLLocationManager alloc] init];
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    _locationManager.delegate = self;
    [_locationManager startUpdatingLocation]; 
}

现在实现如下的委托方法。

-(void)locationManager:(CLLocationManager *)manager
   didUpdateToLocation:(CLLocation *)newLocation
                  fromLocation:(CLLocation *)oldLocation
{
//Your logic to process the location
}