I would like to know if its possible to use the android phone's accelerometer and/or gyroscope to detect changes in altitude. For example, would I be able to detect if I am driving/walking up a hill or down a hill? I am thinking of recording any slight phone motions over some period of time and then using that data to figure out the average up/down motion over that period of time. I just don't know if the sensors would be accurate enough to tell me at least the general direction (i.e. was I going up a hill or down a hill). Also, if I am walking, then I know there will definitely be motion detected, but if I am driving up a hill for example, will I get any motion detected (assuming I sit still in the car)?
-
No. That's going to accumulate wild errors in no time at all. It is also a question which has been asked here many times before. – Chris Stratton Mar 02 '15 at 21:39
-
Can you please provide some links to where it has been asked before? I could not find the one i was looking for, but maybe i didn't search correctly... – Toliy Mar 02 '15 at 21:46
-
Look in the sidebar of the page you are currently viewing. – Chris Stratton Mar 02 '15 at 21:46
-
I looked through those but could not find an answer to my question. I am specifically asking about calculating the overall altitude increase/decrease over time using android sensors. This is my first post on this website, so sorry if I asked the wrong question. I thought i would try it out, but it doesn't look like it's very welcoming to new users :( – Toliy Mar 02 '15 at 21:56
-
I would say that it is .. but it would help your case if you had written that in your question .. e.g. what you had already tried and why it did not work. – cYrixmorten Mar 02 '15 at 21:58
-
Generally speaking, outside of constrained circumstances and aircraft grade components, integrating acceleration to find velocity and integrating that to find total change of position is not workable. That is what the other questions cover. – Chris Stratton Mar 03 '15 at 12:21
-
Thanks Chris, that's what I wanted to know. – Toliy Mar 03 '15 at 15:03
1 Answers
Detecting activity is already a built in feature of the android OS. I have contributed to this library to make it easy to acquire detected activities: https://github.com/mcharmas/Android-ReactiveLocation/
It can detect the states
- IN_VEHICLE The device is in a vehicle, such as a car.
- ON_BICYCLE The device is on a bicycle.
- ON_FOOT The device is on a user who is walking or running.
- RUNNING The device is on a user who is running.
- STILL The device is still (not moving).
- TILTING The device angle relative to gravity changed significantly.
- UNKNOWN Unable to detect the current activity.
- WALKING The device is on a user who is walking.
Returning the detected activity and a confidence ranging between 0 and 100. https://developer.android.com/reference/com/google/android/gms/location/DetectedActivity.html
Regarding your question about altitude, I am not so sure. I recently read a paper where the authors tried to create a Hidden Markov Model to detect some of the activities above, including walking up/down stairs. The problem they encountered was that it is very difficult to differ between walking/up - and down stairs.
I am afraid that an attempt to detect altitude would at best be fairly inaccurate.
Another option might be to use GPS, though it requires some special care as well due to inaccuracy: Android: How to get accurate altitude?

- 1
- 1

- 7,110
- 3
- 25
- 33
-
Thanks cYrixmorten. It might be useful to know the activity. I am just trying to figure out if it would be possible to calculate the altitude change over some time while doing any of those activities. I am planning to use the GPS to get the distance traveled, but would not want to use it to get elevation. I haven't tried implemented anything yet, I wanted to get some opinions on whether it is possible first. I am working on a proposal for school project so I would like to know if i can go in this direction or not. – Toliy Mar 02 '15 at 22:04
-
If you already plan on using GPS, I would think that is the best sensor to utilize. Accelerometer data is pretty noisy, making it difficult to extract such data. – cYrixmorten Mar 02 '15 at 22:18
-
I would like to calculate the altitude difference aside from GPS, I want to use GPS for the coordinates. For example, say I am interested in the altitude/elevation change between point A and point B. I would use GPS to figure out when I am at point A, at which point I would start recording the device motions until i reach point B. Then using the motion data collected, I would like to calculate the altitude difference between those 2 points. – Toliy Mar 02 '15 at 22:33
-
I get that, but altitude (though it might need some adjustments as stated in the SO answer linked at the bottom of my answer) is already part of the data that GPS Locations communicate. So I do not see any reason to get altitude data from a second, and more unreliable, source? – cYrixmorten Mar 02 '15 at 22:53