使用 corelocation 框架计算速度显示在模拟器中而不是设备中-ios8

calculate speed using corelocation framework is showing in simulator not in device-ios8

我使用核心位置框架计算速度如下。但是它在模拟器而不是设备中工作(在设备中它显示 -1)。

  self.curSpeedLabel.text = [NSString stringWithFormat:@"%.2f km/h", newLocation.speed];


 - (void)locationManager:(CLLocationManager *)manager
 didUpdateLocations:(NSArray *)locations
 {
 loc = locations.lastObject;
  if (_startDate == nil) // first update!
 {
    _startDate = loc.timestamp;
    totalDistance = 0;
 }
 else
 {
    totalDistance += [loc distanceFromLocation:_lastLocation];
    CLLocationDistance distanceChange = [loc 
    distanceFromLocation:_lastLocation];
    NSTimeInterval sinceLastUpdate = [loc.timestamp
   timeIntervalSinceDate:_lastLocation.timestamp];
   // speedLabel.text=[NSString stringWithFormat:@"%.f km/h", 
 // (distanceChange)/(sinceLastUpdate)];
  self.curSpeedLabel.text = [NSString stringWithFormat:@"%.2f km/h",
   loc.speed];
    _lastLocation = loc;
   distanceLabel.text =[NSString stringWithFormat:@"%.2f km/h", 
  (totalDistance/metersInKM)];
  NSTimeInterval travelTime = [loc.timestamp 
   timeIntervalSinceDate:_startDate];        
    if (travelTime > 0)
    {
        avgSpeed = (totalDistance) / (travelTime);
       _avgSpeed.text = [NSString stringWithFormat: @"%.2f km/h", avgSpeed];
        NSLog(@"Average speed %.2f", avgSpeed);
        _totTimetaken=(travelTime/60/60);

    }
 }
}

请指教

This value reflects the instantaneous speed of the device in the direction of its current heading. A negative value indicates an invalid speed. Because the actual speed can change many times between the delivery of subsequent location events, you should use this property for informational purposes only.

因此,当您想要更频繁地获得积分时,这实际上应该可以提高您的速度。 既然有距离,可以考虑用距离求速度