Panagiotis Triantafyllou

telematics fix

......@@ -256,7 +256,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
//TODO: comment the first block and uncomment the second block if needs revert to handler implementation
if (mLatitude != 0 && mLongitude != 0) {
mSpeed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " m/s^2");
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(mSpeed)) + " km/h");
}
......@@ -321,7 +321,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
private void initViews() {
mTvVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 km/h");
}
private void requestLocationUpdates() {
......@@ -352,7 +352,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
@Override
public void run() {
double speed = calculateSpeed(mLatitude, mLongitude, location.getLatitude(), location.getLongitude(), (LOCATION_UPDATE_INTERVAL / 1000));
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " m/s^2");
mTvAvgVelocity.setText(String.format("%.1f", Math.floor(speed)) + " km/h");
mLocationHandler.postDelayed(this, LOCATION_UPDATE_INTERVAL);
}
};
......@@ -368,8 +368,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
// Function to calculate speed in meters per second
private double calculateSpeed(double lat1, double lon1, double lat2, double lon2, double timeDifferenceInSeconds) {
double distance = calculateDistance(lat1, lon1, lat2, lon2);
// return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
return (distance / timeDifferenceInSeconds); // Convert to km/h;
return (distance / timeDifferenceInSeconds) * 3.6f; // Convert to km/h;
}
private void requestSingleLocationUpdate() {
......@@ -446,7 +445,7 @@ public class TelematicsActivity extends Activity implements View.OnClickListener
touchCount = 0;
mSensorManager.unregisterListener(this);
mTvVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 m/s^2");
mTvAvgVelocity.setText("0.0 km/h");
Snackbar.make(mLlTelematicsMain, "Sensor Unregistered", Snackbar.LENGTH_SHORT).show();
if (mHandler != null)
mHandler.removeCallbacks(mRunnable);
......