Reputation: 528
I'm trying to determine the location of my users and I have everything setup properly but my devices return -1 for speed and course all the time. When I run the exact same setup on the simulator speed and course values are just fine.
I have calibrated the compass on my test devices and the maps show the correct locations. I have also reset location and privacy settings and I have used 5 different phones. It's always the same story on all devices.
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);
}
}
This returns this:
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"
)
Does anyone have an idea what's going on?
Upvotes: 2
Views: 1705
Reputation: 528
As it turns out CLLocationManager does not return any speed or course information if you
a. don't move at all. A fixed location always has -1 values (should return something else in my opinion but oh well).
b. haven't let the location manager run for a little while. If you stop the location manager immediately after you have created and started it, it does not yet know any of these information (again should return something different in my opinion then "invalid value").
In my case I was doing both of these things and as it turns out none of my devices are broken... (phew)
I made a little application and put it on Github to help others understand this problem. Just put it on your phone and move around for a little while. It will eventually return something but just not immediately and not if you don't move and haven't moved in a while.
Upvotes: 5