我使用 GPS 测量行进距离。问题是 GPS 有时长时间不更新位置变化。
有什么解决办法吗?
locationListen = new LocationListener() {
public void onLocationChanged(Location currentLocation) {
if (prevLocation != null){
test = currentLocation.distanceTo(prevLocation);
distance+=test;
}
prevLocation = currentLocation;
}
public void onStatusChanged(String provider, int status, Bundle b) {
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
Toast.makeText(MainActivity.this,
"Status Changed: Out of Service " + provider,
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Toast.makeText(
MainActivity.this,
"Status Changed: Temporarily Unavailable "
+ provider, Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
Toast.makeText(MainActivity.this,
"Status Changed: Available " + provider,
Toast.LENGTH_SHORT).show();
break;
}
}
public void onProviderDisabled(String s) {
}
public void onProviderEnabled(String s) {
}
};
startOperation.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View but) {
if (startOperation.getText().equals("Start Calculating Fare")) {
mHandler.post(run);
myManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 1000, 10,
locationListen);
startOperation.setText("Stop the calculations");
} else {
mHandler.removeCallbacks(run);
myManager.removeUpdates(locationListen);
finalInfos();
}
}
});
我的位置监听器代码。它只是使用 GPS 更新。正如我所说,GPS有时太长而无法检测到位置