CLLocationManager始终返回速度:-1

时间:2015-05-07 10:18:26

标签: ios cllocationmanager

我正在尝试确定用户的位置,并且我已正确设置所有设置,但我的设备始终返回-1以获得速度和航向。当我在模拟器上运行完全相同的设置时,速度和路线值都很好。

我已经在我的测试设备上校准了指南针,地图显示了正确的位置。我还重置了位置和隐私设置,我使用了5种不同的手机。所有设备上的故事都是一样的。

manager = [[CLLocationManager alloc] init];
self.manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
manager.distanceFilter = 500;
manager.activityType = CLActivityTypeOther;
[manager startUpdatingLocation];



-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    for (CLLocation *location in locations) {
        //double speed = 0.0;
        //speed = location.speed;
        //NSLog(@"%f", s);
        NSLog(@"%@", location.description);
    }
}

这会返回:

2015-05-07 12:16:57.703 Health_[323:84932] Location: (
    "<+52.55719238,+11.02049967> +/- 165.00m (speed -1.00 mps / course -1.00) @ 07.05.15 12:16:57 Mitteleurop\U00e4ische Sommerzeit"
)

有没有人知道发生了什么?

1 个答案:

答案 0 :(得分:4)

事实证明,如果您

,CLLocationManager不会返回任何速度或课程信息

一个。根本不动。一个固定的位置总是有-1个值(在我看来应该返回别的东西但是很好)。

湾避免让位置经理运行一段时间。如果您在创建并启动位置管理器后立即停止它,它还不知道任何这些信息(在我看来应该返回不同的东西&#34;无效值&#34;)。

在我的情况下,我正在做这两件事,因为事实证明我的设备都没有被破坏......(phew)

我制作了一个little application并将其放在Github上以帮助其他人理解这个问题。只需将它放在手机上并移动一会儿即可。它最终将返回一些东西,但不会立即返回,如果你不移动并且避开了一段时间,它就会失败。