how to use android linear acceleration to get current location
<p>I'm trying to make a simple app that shows the user where is his phone compared to the starting point. For example if the phone moved a meter on the x-axis and 2 meters on the y axis then it is supposed to show x:1 y:2 z:0 (or -1 ,-2, depends on which way it moved)</p>

<p>I tried to integrate the acceleration twice to get location but I'm getting some odd results' as if the phone is moving even when it lays still.
Here's my code:</p>

<pre><code>public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() ==Sensor.TYPE_LINEAR_ACCELERATION){
        long now = event.timestamp;
        if(lastEvent==0){
            lastEvent=now;
        }
        interval = now - lastEvent;
        lastEvent = now;
        dt=((float) interval)* (float)0.000000001; /// event timestamp is in nannoseconds
        for(int i=0;i&lt;3;i++)
        {
            location[i]=location[i]+v0[i]*dt+event.values[i]*dt*dt/2;
            v0[i]=v0[i]+event.values[i]*dt;

        }
        x.setText("x: "+location[0]); //// textviews
        y.setText("y: "+location[1]);
        z.setText("z: "+location[2]);
        }
    return; 
}
</code></pre>

<p>Am i on the right track or is it way off?</p>
