#pragma mark --高德定位
- (void)configLocationManager
{
self.locationManager = [[AMapLocationManager alloc] init];
[self.locationManager setDelegate:self];
//设置期望定位精度
[self.locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
// //设置不允许系统暂停定位
// [self.locationManager setPausesLocationUpdatesAutomatically:NO];
// //设置允许在后台定位
// [self.locationManager setAllowsBackgroundLocationUpdates:YES];
//设置定位超时时间
[self.locationManager setLocationTimeout:10];
//设置逆地理超时时间
[self.locationManager setReGeocodeTimeout:5];
}
//单次定位
- (void)locAction
{
//进行单次定位请求
[self.locationManager requestLocationWithReGeocode:NO completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
{
if (error != nil && error.code == AMapLocationErrorLocateFailed)
{
//定位错误:此时location和regeocode没有返回值,不进行annotation的添加
NSLog(@"定位错误:{%ld - %@};", (long)error.code, error.localizedDescription);
return;
}
else
{
self.coords = location.coordinate;
}
}];
}