Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 利用核心运动计算速度_Ios_Objective C_Iphone_Geolocation_Core Motion - Fatal编程技术网

Ios 利用核心运动计算速度

Ios 利用核心运动计算速度,ios,objective-c,iphone,geolocation,core-motion,Ios,Objective C,Iphone,Geolocation,Core Motion,这是我寻找速度的代码。它在模拟器(高速公路驾驶)中运行良好,但在实际设备中,如果我停下来或移动缓慢,它就会像8到10秒钟内的更新一样缓慢更新 CLLocation *locationLast=[[AppDelegate sharedDelegate].arrayLocations lastObject]; CLLocation *locationSecondLast=[[AppDelegate sharedDelegate].arrayLocations objectAtIndex:[[App

这是我寻找速度的代码。它在模拟器(高速公路驾驶)中运行良好,但在实际设备中,如果我停下来或移动缓慢,它就会像8到10秒钟内的更新一样缓慢更新

CLLocation *locationLast=[[AppDelegate sharedDelegate].arrayLocations lastObject];

CLLocation *locationSecondLast=[[AppDelegate sharedDelegate].arrayLocations objectAtIndex:[[AppDelegate sharedDelegate].arrayLocations count]-2];
CLLocationSpeed speed = locationLast.speed - locationSecondLast.speed;
lblSpeedDiffrence.text = [NSString stringWithFormat:@"%.4f MPH", (float)(speed * 2.23693629)];
NSTimeInterval timeDifference = [locationLast.timestamp timeIntervalSinceDate:locationSecondLast.timestamp];
lblTimeDiffrence.text = [NSString stringWithFormat:@"%f seconds", timeDifference];
double HardAcceleration = (speed * 2.23693629) / timeDifference;
if (HardAcceleration>0)
{
     if (HardAcceleration>10)
         lblStatus.text = @"Hard Acceleration";
     else
         lblStatus.text = @"Acceleration";
}
else if (HardAcceleration<0)
{
     if (HardAcceleration<-10)
         lblStatus.text = @"Hard Deceleration";
     else
         lblStatus.text = @"Deceleration";
}
else
{
     lblStatus.text = @"Neutral";
}
CLLocation*locationLast=[[AppDelegate sharedDelegate].arrayLocations lastObject];
CLLocation*locationSecondLast=[[AppDelegate sharedDelegate].arrayLocations objectAtIndex:[[AppDelegate sharedDelegate].arrayLocations count]-2];
CLLocationSpeed speed=locationLast.speed-LOCATIONSEXTLAST.speed;
lblSpeedDiffrence.text=[nsstringstringwithformat:@“%.4f MPH”(浮动)(速度*2.23693629)];
NSTimeInterval时差=[locationLast.timestamp timeIntervalSinceDate:locationSecondLast.timestamp];
lblTimeDiffrence.text=[NSString stringWithFormat:@“%f秒”,时差];
双硬加速=(速度*2.23693629)/时差;
如果(硬加速>0)
{
如果(硬加速>10)
lblStatus.text=@“硬加速”;
其他的
lblStatus.text=@“加速度”;
}

else if(HardAcceleration)让我们知道您面临的问题或您遇到的错误类型。@mqa我没有面临任何错误,但我希望在实际设备中测试代码时获得准确的速度。该代码在模拟器中运行良好,但在实际设备中运行不正常。有没有关于使用核心运动(加速计)查找速度的建议让我们知道您面临的问题或您遇到的错误类型。@我没有遇到任何错误,但我希望在实际设备中测试我的代码时获得准确的速度。该代码在模拟器中运行良好,但在实际设备中不起作用。是否有使用核心运动(加速计)查找速度的建议