- Home /
Device altitude change not accurate
I am working on a project that currently gets accurate position changes by taking the gps coordinates and using the haversine formula to track the devices movement. We also want the device to get the altitude change while the player moves. Location has an altitude that I am recording the highest and lowest points seen and just taking highest minus lowest to find the total altitude change but I get very large readings just walking across my house. These numbers are about 100 or higher typically.
private float highest; private float lowest;
//each time I get the current location info I record this.
if(Input.location.lastData.altitude > highest) { highest = Input.location.lastData.altitude; } if(Input.location.lastData.altitude < lowest) { lowest = Input.location.lastData.altitude; }
//At the end of the walk I just resolve it like this.
float heightDistance = highest - lowest;
Sorry thought that was clear $$anonymous$$y question is does anyone know of a way to get accurate altitude changes or what is wrong with the way I am doing this.
I assume you're doing the various things mentioned in the documentation to make sure location services have started, etc...?
If you modify their example so it loops and logs out the altitude does it give you the same varying results or are they more stable? That would deter$$anonymous$$e whether it's something in your code or something with the GPS itself.
Yea I have the location service started and have tried multiple low numbers for the accuracy (10, 5, 1). I currently use it for horizontal travel at it is accurate for that its just my altitude that is way off. The code I listed above is all I use for altitude since it just seems to be a number for the current altitude.
Can you use the code from the example? Log the values as you walk around, then eyeball them to see if they have the same wide variation as your code is showing. That will show if there's a problem in your code or not.
It could be that you're just occasionally getting a large value but most of the samples are accurate. But you can't tell that with your current code. By logging a bunch of values you can get a better idea what the data looks like.
If it ends up being just the occasional sample that's off then you can do some kind of filtering on the data.