gpt4 book ai didi

ios - CLLocation Manager startUpdatingLocation第二次调用不起作用

转载 作者:行者123 更新时间:2023-12-01 18:17:36 40 4
gpt4 key购买 nike

嗨,我正在我的应用程序中实现位置服务。首先,我必须知道我的坐标才能获得列表中某些位置与设备之间的距离。然后,如果我去某个地方可以进行检查,那么我需要再次获取坐标,问题就在这里。第二次我尝试获取坐标时,没有调用-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations方法。并且我无法获取新的坐标。

我的经理位于具有以下代码的NSObject子目录中:

(id)init {
if ( self = [super init] ) {
if ([CLLocationManager locationServicesEnabled])
{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
}
}
return self;
}

-(void) checkLongLatitudeAgain {
[locationManager startUpdatingLocation];
}

#pragma mark Delegates de CLLocationManager
//
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
NSLog(@"LON%f", manager.location.coordinate.longitude);
NSLog(@"LAT:%f", manager.location.coordinate.latitude);
NSTimeInterval howRecentNewLocation = [newLocationeventDate timeIntervalSinceNow];

if (manager.location.horizontalAccuracy <= 100.0 && howRecentNewLocation < -0.0 && howRecentNewLocation > -20.0){
//Usar coordenada
[self.delegate getLocationForCheckIn:manager.location];
[self stopUpdatingLocation:@"Fins"];
}
}
// ---------------------------------------------------------------------------------------------------------------------
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{
//
if ([error code] != kCLErrorLocationUnknown) {
[self stopUpdatingLocation:NSLocalizedString(@"Error", @"Error")];
}
//
}
// ---------------------------------------------------------------------------------------------------------------------
- (void)stopUpdatingLocation:(NSString *)state {
//Detenemos la lectura del GPS
[locationManager stopUpdatingLocation];
locationManager.delegate = nil;
NSLog(@"Stop gps");
//
}

打开场所列表时,以及在场所内用户按下checkIn按钮时,我都叫该类。两次我都使用此代码:
WPLocationManager *location = [[WPLocationManager alloc]init];
[location checkLongLatitudeAgain];

最佳答案

您每次都在创建新的经理:

WPLocationManager *location = [[WPLocationManager alloc]init];
[location checkLongLatitudeAgain];

该新经理未分配给任何代表。

您需要使用之前创建并分配给您的代表的经理,例如:
[locationManager checkLongLatitudeAgain];

关于ios - CLLocation Manager startUpdatingLocation第二次调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20286919/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com