【发布时间】:2014-01-05 04:16:31
【问题描述】:
我正在使用 CoreLocation 来获取用户位置。我需要获取用户位置,然后将其发送到服务器。我有这一切工作,但是!我正在执行locationManager:(CCLLocationManager *)manager...
在找到该位置之前,我的 url 请求已命中。最好的方法是:
- 请求位置
- 存储在字符串中
- 向请求发送字符串
我想确保在发送之前找到该位置。我是否使用条件检查类的实例并且在块内命中服务器。我不用一直更新,抓一次就stopUpdatingLocation
之前浏览过这篇文章:Getting Longitude/Latitude of the User When the viewDidLoad
到目前为止我所拥有的:
- (void)viewDidLoad {
[super viewDidLoad];
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
[locationManager startUpdatingLocation];
...more below... server request below here
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"didUpdateToLocation: %@", newLocation);
CLLocation *currentLocation = newLocation;
if (currentLocation != nil) {
NSLog(@"found!");
[locationManager stopUpdatingLocation];
}
}
关于如何做到这一点的想法?我认为条件可能有效,但不确定是否有适当的方法使用 CoreLocation 提供的方法来处理它。
【问题讨论】:
标签: ios objective-c core-location