Search code examples
androidgpsaccelerometer

Android: Read GPS + Accelerometer Sensor Simultaneously


I am attempting to make it so that I can read the GPS data which is triggered as an event every one minute, and as a result will also read the accelerometer data at the same time. However I am unable to do this I have attached what I have in my main file. Any help would be appreciated.

https://gist.github.com/4395787


Solution

  • You are making request for GPS updates at 60000 milliseconds

    Line 151

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0,
                locationListener);
    

    So make also accelerometer requests also at 60000 milliseconds (60000000 microseconds)

    Line 71

    sensorManager.registerListener(this,
                sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
                60000000 );
    

    This will give you updates on almost same time if both your listeners start almost same time.