开发者

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜