我locationManager
在我的应用程序中调用了 a,并在各种方法中delegate
引用了 getUserLatitude 和 getUserLongitude 函数。viewDidAppear
viewControllers
我的问题是我的viewDidAppear
方法启动太快,appDelegate
无法找到用户,我得到 0.000000latitude
和 0.000000 longitude
。有谁知道我该如何解决这个问题?谢谢!
我的 appDelegate 由以下位置方法构成:
- (NSString *)getUserCoordinates
{
NSString *userCoordinates = [NSString stringWithFormat:@"latitude: %f longitude: %f",
locationManager.location.coordinate.latitude,
locationManager.location.coordinate.longitude];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone; // whenever we move
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
[locationManager startUpdatingLocation];
return userCoordinates;
}
- (NSString *)getUserLatitude
{
NSString *userLatitude = [NSString stringWithFormat:@"%f",
locationManager.location.coordinate.latitude];
return userLatitude;
}
- (NSString *)getUserLongitude
{
NSString *userLongitude = [NSString stringWithFormat:@"%f",
locationManager.location.coordinate.longitude];
return userLongitude;
}
我正在使用这段代码从 appDelegate 获取更新的位置:
- (void)viewDidAppear:(BOOL)animated
{
NSString *userLatitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate
getUserLatitude];
NSString *userLongitude =[(PDCAppDelegate *)[UIApplication sharedApplication].delegate
getUserLongitude];
}