整理下在使用百度地圖的過程中新發(fā)現(xiàn)的問題,在首頁中我正常調(diào)用了百度地圖iOS的API,代理也正常返回,但是在使用過程中始終無法彈出系統(tǒng)的詢問位置權(quán)限的彈出框,后整理發(fā)現(xiàn)是因?yàn)榘俣鹊貓D無法觸發(fā)iOS自身的定位系統(tǒng),如果想要彈出系統(tǒng)的位置授權(quán)框就需要在首頁之前,使用iOS系統(tǒng)的CLLocationManager來提前定位
上代碼
首先遵循代理CLLocationManagerDelegate
然后定義屬性
@property (nonatomic, strong) CLLocationManager *locationManager;
- 懶加載
- (CLLocationManager *)locationManager {
if (!_locationManager) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.distanceFilter = kCLLocationAccuracyHundredMeters;
if (SSystemVersion.floatValue > 8.0) {
[_locationManager requestWhenInUseAuthorization];
}
}
return _locationManager;
}
- 開始定位
-(void)startUserLocation
{
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}