Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.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
Objective c CLLocationSpeed问题_Objective C - Fatal编程技术网

Objective c CLLocationSpeed问题

Objective c CLLocationSpeed问题,objective-c,Objective C,我试图让我的代码返回设备的速度(以英里/小时为单位),如下所示: double speed = newLocation.speed; NSString *speedyspeed = [NSString stringWithFormat:@"%d", (speed*2.2369)]; yourSpeed.text = speedyspeed; “speed*2.2369”应该是为了纠正这样一个事实,即返回的速度是米/秒,而不是我想要的英里/小时。不管怎样,我得到的值是,-173498723,而不

我试图让我的代码返回设备的速度(以英里/小时为单位),如下所示:

double speed = newLocation.speed;
NSString *speedyspeed = [NSString stringWithFormat:@"%d", (speed*2.2369)];
yourSpeed.text = speedyspeed;
“speed*2.2369”应该是为了纠正这样一个事实,即返回的速度是米/秒,而不是我想要的英里/小时。不管怎样,我得到的值是,-173498723,而不是正常值。我显然做错了什么。然后,速度值字符串被分配到名为“yourSpeed”的UILabel的输出

有什么建议吗


谢谢

您应该使用%f而不是%d,因为您使用的是double,而不是整数

资料来源: