Android GPS Tracking Returning Odd Results -
i've encountered strange numbers while tracking data using gps on htc one. in essence, have function calculates approximate difference between 2 gps locations, results are... odd.
the first reading reasonable, , next readings 0.0km until 5th or sixth.
i calculate distance every 10 seconds, while moving @ 50km/h naturally, i'd expect other 0.0km every reading.
could spot problem is? there limit on how many times can gps readings? thanks!
here sample of data going @ 50 km/h taking readings every 10 seconds:
186m 0.0m 0.0m 0.0m 190m 0.0 ... public class profile extends activity { gpstracker gps; private double long1, lat1; public static double haversine( double lat1, double lng1, double lat2, double lng2) { int r = 6371; // average radius of earth in km double dlat = math.toradians(lat2 - lat1); double dlon = math.toradians(lng2 - lng1); double = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.toradians(lat1)) * math.cos(math.toradians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2); double c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)); double d = r * c; return d*1000.00; } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_profile); gps = new gpstracker(profile.this); if(gps.cangetlocation()) { lat1 = gps.getlatitude(); long1 = gps.getlongitude(); } final handler handler = new handler(); timer timer = new timer(); timertask doasynchronoustask = new timertask() { @override public void run() { handler.post(new runnable() { @suppresswarnings("unchecked") public void run() { try { if(gps.cangetlocation()) { gps = new gpstracker(profile.this); double latitude = gps.getlatitude(); double longitude = gps.getlongitude(); double distance = haversine(lat1, long1, latitude, longitude); toast.maketext( getapplicationcontext(), string.valueof(distance) + " meters", toast.length_long).show(); long1 = longitude; lat1 = latitude; } else { gps.showsettingsalert(); } } catch (exception e) { // todo auto-generated catch block } } }); } }; timer.schedule(doasynchronoustask, 0, 10000); } }
what gpstracker class?
my guess first results calculated using wi-fi , cell towers (using network provider) , return same approximate location. after time gps fix , start getting more accurate location info.