【发布时间】:2013-07-10 17:05:54
【问题描述】:
我有这个代码:
Location newLocation = new Location(LocationManager.GPS_PROVIDER);
Location oldLocation = new Location(LocationManager.GPS_PROVIDER);
float distanceTravelled=0;
onLocationChanged:
@Override
public void onLocationChanged(Location location)
{
oldLocation.set(newLocation);
startactivity();
distanceTravelled+=newLocation.distanceTo(oldLocation);
String stringDistance= Float.toString(distanceTravelled);
TextView distance = (TextView) findViewById(R.id.textDistance);
distance.setText(stringDistance);
}
开始活动:
public void startactivity()
{
GPSTracker gps = new GPSTracker(Live.this);
if(gps.canGetLocation())
{
double latitude = gps.getLatitude();
double longitude = gps.getLongitude();
Toast.makeText(getApplicationContext(), "Your Location is: \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
newLocation.setLatitude(latitude);
newLocation.setLongitude(longitude);
}
else
{
gps.showSettingsAlert();
}
}
GPSTracker 是一个单独的类,它获取当前的纬度和经度(它工作正常!)。
GPS 更新至少。距离 5 米和分钟。时间 5 秒。
这是我的完整 GPSTracker 课程:GPSTracker.java
我在 manifest 中添加了三个权限:fine、coarse 和 internet。
我的问题是 onLocationChanged 中的文本视图永远不会改变。
有什么问题?是 onLocationChanged 没有被调用还是存在一些逻辑错误(距离始终保持为零)?
以及如何解决这个问题?
【问题讨论】:
标签: java android eclipse gps location