我有一个getLocation
方法可以初始化 myCLLocationManager
并调用startUpdatingLocation
. 在我得到用户的位置后,我打电话给stopUpdatingLocation
.
稍后,当用户按下刷新时,我会调用一个调用方法reloadData
,getLocation
以便获取用户的最新位置。但是,这永远不会调用该locationManager:didUpdateToLocation:fromLocation
方法..所以我永远不会得到用户的最新位置。可能是什么问题?
-(void) getLocation {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}
- (void) locationManager: (CLLocationManager *)manager
didUpdateToLocation: (CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
if (oldLocation!= nil) { // make sure to wait until second latlong value
[self setLatitude:newLocation.coordinate.latitude];
[self setLongitude: newLocation.coordinate.longitude];
[self.locationManager stopUpdatingLocation];
self.locationManager.delegate = nil;
self.locationManager = nil;
[self makeUseOfLocationWithLat:[self getLatitude] andLon:[self getLongitude]];
}
}
-(void) reloadData {
[self getLocation];
}