gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 02:17:42 24 4
gpt4 key购买 nike

我正在使用核心位置框架计算如下速度。然而,它在模拟器中而不是在设备中工作(在设备中它显示 -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.

因此,当您想要更频繁地获得积分时,这实际上应该可以提高您的速度。由于您有距离,请考虑使用距离来计算速度。

关于ios - 使用 corelocation 框架计算速度显示在模拟器中而不是在 device-ios8 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28562811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com