Reputation: 923
I'm creating an application that gets the users speed whilst driving using the Android Location class. The problem that I am facing is that every post on a forum or article explains problems with the getSpeed() method. Having just gone into my car to test several times, it returns 0. I am not sure why, just wondering if anyone has been able to find out why and how to get the actual speed?
Thanks in advance
Upvotes: 0
Views: 1207
Reputation: 4705
getSpeed works just fine, provided you have a capable GPS hardware in your device and you have enough satellites in sight. I am using it for a flight logging application.
One issue with getSpeed is, that the emulator will always return 0; even if it is fed with NMEA data which has speed info. So testing requires the real devices.
If the GPS receiver is inside the car, one issue might be, that it cannot acquire enough satellites in time for your test. Try leaving the device near the windshield (if it is not covered with a reflective surface based on something metallic!) and give it time to get a fix. Consider using a GpsStatusListener to get a count of visible satellites.
The trick mentioned above to compute speed from distances of samples requires filtering of the data. The more samples you use the more noise you get (which needs filtering, search for it here, there are several articles on stackoverflow on this topic). The less samples you use the greater is the error when not moving on a straight line.
Upvotes: 1