{
...
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"myLocation1: %@",[locations lastObject]);
myLocation = [locations lastObject];
NSLog(@"myLocation2: %@",[locations lastObject]);
[manager stopUpdatingLocation];
[self doSomethingWithLocation];
}
目前我在位置 40.000,40.000。我正在关闭我的应用程序并将位置更改为 10.000,10.000
当再次进入应用程序并运行[locationManager startUpdatingLocation];
我的日志将显示:
myLocation1: <+40.00000000,+40.00000000>
myLocation2: <+40.00000000,+40.00000000>
如果我[locationManager startUpdatingLocation];
再次触发,我的日志将显示:
myLocation1: <+10.00000000,+10.00000000>
myLocation2: <+10.00000000,+10.00000000>
我怎样才能调用didUpdateLocations
一次并仍然获得当前位置?我应该使用另一个代表吗?
我想我可以放在stopUpdatingLocation
里面doSomethingWithLocation
并doSomethingWithLocation
在某种延迟后运行,以便更新正确的位置,但我确信这不是它的本意。
谢谢