views:

231

answers:

2

I have been stuck on this for days, and was wondering if anyone had any clues? Should be simple, but it has me stuck! I get my location, then continue. But I want to stay IN THAT METHOD - LOOPING - until I get a valid location. Then loadview. THANKS for any tips!

I am using the standard:

- (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);

    } 


}
+3  A: 

Rather than spinning in your viewDidLoad, how about putting up a temporary view until you have your GPS location?

// 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;
}

your view will still be under the splash screen waiting, but nobody can interact with it until you're ready.

David Maymudes
A: 

Ok, what the app does is grab my location, then using that (lat/lng), pick from a DB all locations within so many miles of me based on the Haversine formula, then drop those location pins on a map. Right now where I'm stuck is I can grab my location, but still learning the sequence of when the view should pop in.

Thanks for the tips from both guys. Still learning!

ed potter
You should make this an edit to your question, not an answer
colithium