开发者

Getting the Current Location

开发者 https://www.devze.com 2023-03-09 15:24 出处:网络
Say I want to create a function -(void)setCurrentLocationasAnchor { //[self.locationManager startUpdatingLocation];

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

精彩评论

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