目前我的功能是这样的:
#define kKILOMETER 1000
#define kSeconds_To_Milliseconds 1000
#define kHOUR 60
#define kMINUTE 60
#define kLongDistance_3KM 3
- (long)calculateTimeToMilliSecondsWithDistance:(double)distance andSpeed:(float)theSpeed
{
// Distance arrive in meters
double kmDistance = distance/kKILOMETER;
long time =
(long)(((kmDistance - kLongDistance_3KM)/[self.ref integerForKey:@"MAX_SPEED"])*kHOUR*kMINUTE*kSeconds_To_Milliseconds);
NSLog(@"calculateTimeToMilliSeconds -> sleep to (sec): %li, maxSpeed: %li",
time/1000, (long)[self.ref integerForKey:@"MAX_SPEED"]);
[self startSendSleepTime:time];
return time;
}
我的“MAX_SPEED”值是指200 km / h。
我得到的是错误的价值。
我想用我的距离减去3公里,速度为200公里/小时来计算时间,但不知何故,它会搞得一团糟。
在几秒钟内获得它会更好,因为我应该删除kSeconds_To_Milliseconds
,对吗?
我不知道为我搞砸了什么。
编辑1:
例如:
2014-03-19 18:12:39.624 Cellular Radar[3338:60b] Distance to car: 4713, Trap Radius: 900
2014-03-19 18:12:39.673 Cellular Radar[3338:60b] calculateTimeToMilliSeconds -> sleep to (sec): 2055, maxSpeed: 3
2014-03-19 18:12:39.684 Cellular Radar[3338:60b] Sleep for (2055.000000 seconds | 34.250000 minutes | 0.570833 hours)