Getting the Current Location
Say I want to create a function
-(void)setCurrentLocationasAnchor
{
//[self.locationManager startUpdatingLocation];
}
It's job is to set self.currentAnchor
into the current location.
How would I do that?
The only t开发者_开发问答hing I can think of is do [self.locationManager startUpdatingLocation];
and then wait until the delegate
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
is called.
How can I do so in one function?
Any problem in particular in just doing it the way you said? (i.e. waiting for the delegate to be called)
Because if what you want is a synchronous way of getting the location, that'd be blocking the UI, right?... Also, what do you want, just the first location to be returned? Because the longer you wait, the more precision you will get on your location.
Btw, have you considered using CLLocationManager's location property to get a recent location?
精彩评论