Iphone 获取经度、纬度而不设置所有应用程序生命周期

Iphone 获取经度、纬度而不设置所有应用程序生命周期,iphone,objective-c,location,Iphone,Objective C,Location,我想在应用程序启动时简单地获取lan、lon值,我不想在更改位置时每秒更新这些值。我正在使用以下代码: locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; [locationManager startUpdatingLocation]; - (void)locationManager:(CLLocationManager *)manager didUpdateToLocatio

我想在应用程序启动时简单地获取lan、lon值,我不想在更改位置时每秒更新这些值。我正在使用以下代码:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
  {
    latValueNSString = [NSString stringWithFormat: @"%f",newLocation.coordinate.latitude];
    lanValueNSString = [NSString stringWithFormat: @"%f",newLocation.coordinate.longitude];

  }

但问题是我不能传输这些值,因为每毫秒它都会一次又一次地设置它。。。如何将这些值设置为仅一个,仅此而已???

如果您只需要1个值,只需获取第一个位置并告诉位置管理器停止更新位置

[manager stopUpdatingLocation];

调用委托方法时执行此操作。

调用
[locationManager停止更新位置]一旦得到结果。在调用stop之前,您可能需要检查精度是否符合要求。

我如何知道我得到了该值?我试过:
locationManager=[[CLLocationManager alloc]init];locationManager.delegate=self;[locationManager startUpdatingLocation];[管理器停止更新位置]但他看到他从未进入代理。尝试在代理中停止它,但它没有帮助您在收到代理上的位置后必须调用StopUpdateLocation。这就是我所做的,但它继续进入代理中我如何知道我得到了它们?我不能在循环时使用
,因为如果出现问题,它将永远不会结束…请尝试
self.lastnownlocation=nil;[self.locationManager setDesiredAccuracy:2000];[self.locationManager startUpdatingLocation]-(void)locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*)oldLocation{NSLog(@“将位置更新为%@”,newLocation);self.lastKnownLocation=newLocation;if(newLocation.HorizontalAccurance<3000){NSLog(@“停止更新位置。”);[self.locationManager停止更新位置];}}