【发布时间】:2012-08-10 10:47:07
【问题描述】:
我有一个小问题。我在onLocationChanged() 方法上找到了location.getSpeed() 方法,而.getSpeed() 通常在我呆在同一个地方时不会更新/更改为0km/h。
我应该在哪里找到 location.getGpeed() 方法,当我停留在原地时更新显示 0km/h?
还有一个问题。这是我的locationListener:
private final LocationListener locationListener = new LocationListener()
{public void onLocationChanged(Location location) {
boolean var = false;
float distance;
if (firstRun) { distance=0; firstRun=false; }
else
distance = location.distanceTo (startLocation);
Tspeed.setText("0km/h");
if (location.getSpeed()!=0)
{
Tspeed.setText(""+(location.getSpeed()*3600/1000 +"km/h"));
}
else
{
Tspeed.setText("0km/h");
}
sAllDistance += distance; //
startLocation=location;
Tdistance.setText(""+(int)SAllDistance+" m");
}
问题是:当LocationManager 得到修复时,从location.distanceTo() 返回的第一个AllDistance 是±50 米。
我该如何解决?
【问题讨论】: