【问题标题】:distanceFromLocation returns huge value without moving the tiniest bitdistanceFromLocation 返回巨大的价值而不移动最微小的位
【发布时间】:2011-12-05 20:59:22
【问题描述】:

我正在尝试调用一个函数,以防自上次检查以来行进的距离 > 30 m。根据 CLLocationDistance 的 Class 描述,返回的值以 m 为单位。

我使用这个代码:

[locationManager startUpdatingLocation];
if (!startingLocation)
    startingLocation = locationManager.location;
//   NSLog(@"Latitude:%f Longitude:%f", startingLocation.coordinate.latitude, startingLocation.coordinate.longitude);

    updatedLocation = locationManager.location;
CLLocationDistance distance = [updatedLocation distanceFromLocation:startingLocation];
if (distance > 30) {
    NSLog(@"%f",distance);
    NSLog(@"Latitude:%f Longitude:%f", updatedLocation.coordinate.latitude, updatedLocation.coordinate.longitude);
    [self stop];

带有 NSLog 的控制台输出返回 7946754.993111,我什至没有碰手机。 任何建议表示赞赏!

【问题讨论】:

    标签: ios core-location


    【解决方案1】:

    两点之间有 8000 公里?我敢打赌,第一个点是 0、0,你离那里大约 8000 公里,对吧?

    在任何情况下,请确保仅使用有效位置,方法是在使用位置坐标之前检查以确保 Horizo​​ntalAccuracy >=0。无效位置的水平精度为负。

    此外,您可能应该通过检查位置数据的年龄来丢弃任何缓存的位置,如果超过几秒钟就不要使用它。

    请参阅进行这些检查的sample code here

    另一件需要注意的事情是,由于准确性的变化,您可能会获得显示虚假运动的位置。详情请见this answer

    【讨论】:

      【解决方案2】:

      有没有可能是因为您打电话给startUpdatingLocation,然后获取该位置,然后立即要求更新该位置仍在试图找出它的确切位置,因此发生了大动作。

      尝试从另一个方法调用startUpdatingLocation,然后从CLLocationManager 实现委托方法locationManager:didUpdateToLocation:fromLocation 以获取运动。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-29
        • 1970-01-01
        • 1970-01-01
        • 2014-09-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多