java - Moving Vehicle Path Distance Calculation Using Android Device and LocationManager -


any , gives accurate traveled distance example welcomed. tried calculating latitude , longitude. storing previous , current points data , distance , adding every 5 seconds when vehicle speed != 0 checked many rounds of moving vehicle, every time getting different kms distance. not accurate. accuracy solution moving vehicle path distance calculation.

private double journeypathdistance(double currentlat, double currentlng) {     if (isfirsttime && vehiclespeedvalue != 0) {         location loc1 = new location("");         loc1.setlatitude(currentlat);         loc1.setlongitude(currentlng);         location loc2 = new location("");         loc2.setlatitude(currentlat);         loc2.setlongitude(currentlng);         isfirsttime = false;         prevlat = currentlat;         prevlng = currentlng;         distancekms = loc1.distanceto(loc2) / 1000;     } else {         if (vehiclespeedvalue != 0) {             location loc1 = new location("");             loc1.setlatitude(prevlat);             loc1.setlongitude(prevlng);             location loc2 = new location("");             loc2.setlatitude(currentlat);             loc2.setlongitude(currentlng);             prevlat = currentlat;             prevlng = currentlng;             distancekms += (loc1.distanceto(loc2) / 1000);         }     }     return distancekms; } 

you're going have add lot of intelligence on top of near accurate. lets assume you're using gps (if you're using network you're in huge trouble that). gps on phone accurate within 10 meters or so. every data point may off 10 meters. add lot of 10 meter inaccuracies, , you're adding in lot of distance. , you'll occasional point that's way off. there no way make algorithm work adding deltas.

what need filter it. ignore short distance changes, add long ones have multiple confirmed readings (to ensure random wrong location doesn't throw off readings). idea comes mind trying detect turns finding long lasting changes in heading, , figuring out each straightaway begins , ends find length.

of course accurate way know read odometer. presume have reason not things easy way.


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -