我需要从GPS上获得速度和航向.但是,我从location.getSpeed()获得的唯一数字是0或者有时不可用.我的代码:
String provider = initLocManager();
if (provider == null)
return false;
LocationListener locListener = new LocationListener() {
public void onLocationChanged(Location location) {
updateWithNewLocation(location, interval, startId);
Log.i(getString(R.string.logging_tag), "speed =" + location.getSpeed());
}
public void onProviderDisabled(String provider){
updateWithNewLocation(null, interval, startId);
}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
_locManager.requestLocationUpdates(provider, interval, DEFAULT_GPS_MIN_DISTANCE, locListener);
private String initLocManager() {
String context = Context.LOCATION_SERVICE;
_locManager = (LocationManager) getSystemService(context);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(true);
criteria.setSpeedRequired(true);
criteria.setCostAllowed(true);
//criteria.setPowerRequirement(Criteria.POWER_LOW);
String provider = _locManager.getBestProvider(criteria, true);
if (provider == null || provider.equals("")) {
displayGPSNotEnabledWarning(this);
return null;
}
return provider;
}
我试图玩标准,但没有成功.有人有什么想法有什么问题吗?