Ios CLLocationManagerDelegate方法未更新
这是我设置经理的地方:Ios CLLocationManagerDelegate方法未更新,ios,delegates,location,cllocationmanager,Ios,Delegates,Location,Cllocationmanager,这是我设置经理的地方: @property (nonatomic,strong) CLLocationManager *locManager; 这是我的委托方法: -(void) viewDidAppear:(BOOL)animated { self.locManager = [[CLLocationManager alloc] init]; [_locManager setDelegate:self]; [_locManager setDesiredAccuracy:
@property (nonatomic,strong) CLLocationManager *locManager;
这是我的委托方法:
-(void) viewDidAppear:(BOOL)animated
{
self.locManager = [[CLLocationManager alloc] init];
[_locManager setDelegate:self];
[_locManager setDesiredAccuracy:kCLLocationAccuracyBest];
[_locManager setPausesLocationUpdatesAutomatically:NO];
[_locManager setDistanceFilter:1.0];
[_locManager startUpdatingLocation];
}
该方法在启动时被调用三次,然后再也不会调用。
提前感谢您将这段代码保存在
viewdiload:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int degrees = newLocation.coordinate.latitude;
double decimal = fabs(newLocation.coordinate.latitude - degrees);
int minutes = decimal * 60;
double seconds = decimal * 3600 - minutes * 60;
NSString *lat = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
latLabel.text = lat;
degrees = newLocation.coordinate.longitude;
decimal = fabs(newLocation.coordinate.longitude - degrees);
minutes = decimal * 60;
seconds = decimal * 3600 - minutes * 60;
NSString *longt = [NSString stringWithFormat:@"%d° %d' %1.4f\"",
degrees, minutes, seconds];
lonLabel.text = longt;
}
使用此方法:
self.locManager = [[CLLocationManager alloc] init];
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
location_updated = [locations lastObject];
NSLog(@"updated coordinate are %@",location_updated);
}
此方法:
self.locManager = [[CLLocationManager alloc] init];
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
location_updated = [locations lastObject];
NSLog(@"updated coordinate are %@",location_updated);
}
…在iOS 6.0中已被弃用上述方法已被弃用。 请使用此代理
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;
您在iOS模拟器或真实设备中尝试了此操作?为什么需要在委托方法中调用StopUpdateingLocation方法。我想持续监控大约1.0m-10.0m的位置变化。如果您需要持续监控,则可以删除[locationManager StopUpdatengLocation];locationManager=零;