如何在 - (void)locationManager中调用服务:( CLLocationManager *)管理器didUpdateToLocation只有一次?:

时间:2013-09-27 12:13:15

标签: iphone ios ipad

我有一个应用程序,每当指定的位置发生更改时我都需要调用服务。我已经在我的委托类中启动了位置控制器,就像这样

    locationController = [[UILocation alloc] init];
    locationController.delegate = self;
    locationController.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationController.locationManager.distanceFilter = 1000.0;
    [locationController.locationManager startUpdatingLocation];  

但是每个人都知道Accuracybest会以不一致的方式多次调用didupdate方法。那么我怎样才能从委托方法中调用我的服务一次?有人能指出我如何实现这一目标吗?

2 个答案:

答案 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];
}

当第一次更新位置时,它将停止位置更新。