【问题标题】:didUpdateLocations delegate method doesn't get called for small distance location changes小距离位置更改不会调用 didUpdateLocations 委托方法
【发布时间】:2014-08-13 22:40:40
【问题描述】:

我正在使用模拟器并更改位置以模拟设备的移动。

我发现的问题是:

在下面的代码中,当我尝试打印纬度和经度值时,该值被四舍五入为 6 个十进制数字(43.825885,-75.839785),而我在模拟器中输入的原始值(调试->位置)是 43.82588498,-75.83978498。 (对于这些初始值,调用 didUpdateLocations 委托)

现在我输入的下一个位置(就在上一个位置旁边)是 43.82499145,-75.84050195,我必须得到 43.824991,-75.840502。但是这次没有调用 didUpdateLocations 委托。

但是当我现在给出 43.82110323,-75.85291386(四舍五入为 43.821103,-75.852914)时,这次调用了 didUpdateLocation 委托。

  • (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *) 位置 {

     CLLocationCoordinate2D coordinate = [[locations lastObject] coordinate];
     NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
     NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
    
     NSLog(@"here Latitude : %@", latitude);
     NSLog(@"here Longitude : %@",longitude);
    

    }

以下是我的 locationManager 属性:

    _locationManager = [[CLLocationManager alloc] init];
    [_locationManager setDelegate:self];
    [_locationManager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [_locationManager setDistanceFilter:300];
    [_locationManager startUpdatingLocation];
    [_locationManager startUpdatingHeading];

这是我的 mapView 对象的设置:

    self.mainMapView.delegate=self;
    [self.mainMapView setShowsUserLocation:YES];

这是因为操作系统正在四舍五入 Lat/Lon 值吗?还是因为我使用的是模拟器(我认为这不是问题,因为当我阅读类似的问题时,人们提到如果你模拟位置,那么应该没有任何问题)?

我没有 iOS 设备。 didUpdateLocation 是否仍有可能在实际设备上正常工作?

我无法找出这里的错误。我希望每次进行最轻微的位置更新时都调用 didUpdateLocations 委托。请指导我。

【问题讨论】:

    标签: ios objective-c ios7 mapkit core-location


    【解决方案1】:

    尝试删除您的 setDistanceFilter 并让 locationManger 使用默认值 (kCLDistanceFilterNone)。距离过滤器告诉您的位置管理器仅在设备移动了该数量或超出该数量时才调用 didUpdateLocations。因此,在您的情况下,它将每 300 米更新一次位置。

    【讨论】:

      【解决方案2】:

      您需要做的第一件事是将以下一个或两个键添加到您的 Info.plist 文件中: NSLocationWhenInUseUsageDescription NSLocationAlwaysUsageDescription

      接下来您需要为相应的定位方法,WhenInUse 或 Background 请求授权。使用以下调用之一: [self.locationManager requestWhenInUseAuthorization] [self.locationManager requestAlwaysAuthorization]

      // 检查 iOS 8 if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.locationManager requestWhenInUseAuthorization]; }

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多