0

我已经坚持了好几天了,想知道是否有人有任何线索?应该很简单,但它让我卡住了!我得到了我的位置,然后继续。但我想保持这种方法 - 循环 - 直到我得到一个有效的位置。然后加载视图。感谢您的任何提示!

我正在使用标准:

- (id)init
{
    if (self = [super init])
    {
        self.locationManager = [[[CLLocationManager alloc] init] autorelease];
        self.locationManager.delegate = self; // send loc updates to myself
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];
    }

    return self;
}



- (void)viewDidLoad
{


 // do my processing here ONLY when I get a valid location***************************  
 // and if I never get a valid location, then just go to my last location.



 }



(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];

    if (abs(howRecent) < 5.0)

    {

        [manager stopUpdatingLocation]

         printf("latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);

    } 


}
4

1 回答 1

3

与其在 viewDidLoad 中旋转,不如在获得 GPS 位置之前建立一个临时视图?

// custom full-screen view class of your choice
//  could just be a UIImageView if you wanted
SplashOverlay *splash;

- (void)viewDidLoad {
    [super viewDidLoad];

    splash = [[SplashOverlay alloc] initWithNibName:@"SplashOverlay" bundle:nil];

    [self.view addSubview:splash.view];
}

// do this code to get rid of the view
- (void) doneWithSplashScreen {
    [splash.view removeFromSuperview];
    [splash release];
    splash = nil;
}

您的视图仍将在初始屏幕下等待,但在您准备好之前没有人可以与之交互。

于 2009-07-03T16:47:44.030 回答