0
我一直堅持這幾天,並想知道如果任何人有任何線索?應該很簡單,但它讓我卡住了!我得到我的位置,然後繼續。但我希望保持這種方法 - 循環 - 直到我獲得有效位置。然後loadview。感謝任何提示!loadview只有當我得到我的GPS位置
我使用的標準:
- (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);
}
}