0

I want to know how I can use accelerometer sensor to determine distance that I an walk it at Android device If it is possible, then how can I implement it?

I use this code but not run. Any answer please??

@Override
public void onSensorChanged(SensorEvent event) {

    float[] values = event.values;
    int value = -1;
    if (values.length > 0) {
        value = (int) values[0];
    }
    if(event.sensor.getType()==Sensor.TYPE_STEP_DETECTOR) {
        steps++;
    }
}

  float distance = (float)(steps*68.475)/(float)100000;
Jefferson
  • 794
  • 10
  • 24
  • you have acceleration, you have time, therefore you have velocity and distance traveled, it is just math. – luk2302 Sep 02 '17 at 21:09
  • how can obtain the acceleration ? – sayed salah Sep 02 '17 at 21:19
  • it's very common issue, with first hit on google you can get bunch of examples check https://stackoverflow.com/questions/22292617/how-to-calculate-distance-while-walking-in-android –  Sep 02 '17 at 21:30

1 Answers1

0

It is not possible: due to the low sensitivity of the built-in accelerometers and the so weak accelerations that are created when a person walks.

Not having network does not mean that GPS does not work ...

from56
  • 3,976
  • 2
  • 13
  • 23
  • https://stackoverflow.com/questions/2741403/get-the-distance-between-two-geo-points – from56 Sep 02 '17 at 21:25
  • ok i able to obtain the location but i want to save start location and end location and measure distance between them @Override public void onLocationChanged(Location location) { displaytv.setText("\n"+location.getLatitude()+" \n"+location.getLongitude()); what can i do ?? – sayed salah Sep 03 '17 at 14:33
  • You save initial and actual positions in Position variables and then distance = initialPos.distanceTo(actualPos); – from56 Sep 03 '17 at 22:18