0

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

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

但众所周知,Accuracybest 会以不一致的方式多次调用 didupdate 方法。那么我怎样才能从委托方法中调用我的服务一次呢?有人能指出我如何实现这一点吗?

4

2 回答 2

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];
}
于 2013-09-27T12:42:11.660 回答
0
-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[manager stopUpdatingLocation];
}

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

于 2013-09-27T13:14:45.767 回答