location.getspeed()更新 [英] location.getspeed() update
问题描述
我有一个豆蔻问题。我所在的 onLocationChanged()
方法,以及 A
通常当我呆在同一个地方不会更新0公里每小时/改变。 location.getSpeed()
方法。 getSpeed()
I have a litte problem. I located a location.getSpeed()
method on the onLocationChanged()
method, and .getSpeed()
usually doesn't update/change to 0km/h when I stay in same place.
我应该在哪里找到 location.getGpeed()
方法,该更新显示0公里每小时的时候我留在原地?
Where should I locate a location.getGpeed()
method, that the update showed 0km/h when I stay in place?
和另外一个问题。这是我的 LocationListener的
:
And another question. This is my 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
得到修复,第一个 AllDistance
从 location.distanceTo()
为±50米。
The problem is: when the LocationManager
get the fix, the first AllDistance
returned from location.distanceTo()
is ±50 meters.
我怎样才能解决这个问题?
How can I fix it?
推荐答案
其实,GPS不会给出确切的信息,所有的时间。即使你住在同一个地方,有些时候,经度和纬度而异一点点。我认为这取决于 minTime
和 minDistance才会
您所提供的 requestLocationUpdates(...)
方法。
Actually, GPS wont give exact information all the time. Even if you stay at same place, some times, latitude and longitude vary a little bit. I think it depends on minTime
and minDistance
you provide to requestLocationUpdates(...)
method.
总之,一旦尝试改变像下面这些值。
Anyway, once try to change these values like below.
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
1000L(minTime), 2000.0f(minDistance), myLocationListener);
希望它帮助。
编辑:
您可以做的一件事是,根据的文档, location.hasSpeed()
收益真正
如果此修订包含速度信息,假
其它。当你住在同一个地方,它返回假
我猜。
One more thing you can do is, according to the documentation, location.hasSpeed()
returns true
if this fix contains speed information, false
otherwise. When you stay at same place, it returns false
I guess.
在此基础上,你可以做一些像的TextView
设定值等。
Based on this, you can do something like setting value for textView
etc.
我还没有尝试过,但你可以尝试一次。
I have not tried but you can try once.
这篇关于location.getspeed()更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!