我有一个应用程序,每当指定的位置发生更改时我都需要调用服务。我已经在我的委托类中启动了位置控制器,就像这样
locationController = [[UILocation alloc] init];
locationController.delegate = self;
locationController.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationController.locationManager.distanceFilter = 1000.0;
[locationController.locationManager startUpdatingLocation];
但是每个人都知道Accuracybest会以不一致的方式多次调用didupdate方法。那么我怎样才能从委托方法中调用我的服务一次?有人能指出我如何实现这一目标吗?
答案 0 :(得分:0)
-(void)postCurrentLocationOfDevice
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
self.locationManager.delegate = self;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CURRENT_LOCATION = [locations objectAtIndex:0];
[self.locationManager stopUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
CURRENT_LOCATION = newLocation;
[self.locationManager stopUpdatingLocation];
}
答案 1 :(得分:0)
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[manager stopUpdatingLocation];
}
当第一次更新位置时,它将停止位置更新。