0

在我的应用程序中,我正在使用 Location 类的 getSpeed() 方法检索设备的速度。它以米/秒为单位给出速度。为了将此值转换为公里/小时,我将其乘以 3.6。但我的速度不对。前任。以 40 公里/小时的速度移动时为 580。这是我的代码:

public void onLocationChanged(Location location)
{   
    float mps = location.getSpeed();
    float kmh = (float) (mps*3.6);
    speed = Float.toString(kmh); 
    Toast.makeText(context,"speed :"+speed,TOAST.LENGTH_LONG).show();
}
4

1 回答 1

1

我正在使用以下代码来获得当前速度,它对我有用。

public static final int HOUR_MULTIPLIER = 3600;
public static final Double UNIT_MULTIPLIERS[] = { 0.001, 0.000621371192 };
public static final int INDEX_MILES = 1;

localspeed = loc.getSpeed() * 1.0; 
localspeed = ((localspeed * HOUR_MULTIPLIER) * UNIT_MULTIPLIERS[INDEX_MILES]);

你可以从link1link2找到教程

于 2013-05-27T11:52:05.710 回答