locationmanager - Android: Issue in calculating distance using Location manager -
Currently I'm working on an application where I want to calculate the distance of the vehicle's travel. I need to drive a car, my Android device should calculate the total distance and send this information to the server. To do this, I set up the Android's Location Manager API, criteria and used getBestProvider. In this way we can either use GPS or network for latitude and longitude. The following code snippet is as follows:
locationManager = (LocationManager) getSystemService (context.LOCATION_SERVICE); Criterion Criteria = new criteria (); Criteria.setAccuracy (Criteria.ACCURACY_FINE); Criteria.setPowerRequirement (Criteria.POWER_HIGH); Provider = locationManager.getBestProvider (Criteria, Incorrect); LocationManager.requestLocationUpdates (provider, 30000,5, this); onLocationChanged () call back method provide latitude and longitude each time. We always store the previous coordinates and when we get new coordinates, then we get two distance between the distance () the following code snippet is the following:
at public place Location change (location location) {findLatLongDistance (location); } Private What Look Lite Long Distance (Place Location) [// Todo Auto-Generated Method Stub Trial {Date Date = New Date (); Timestamp2 = sdf.format (date); GetSavedLatLong (); // Preferred position and long position space B = new place ("point B"); LocationB.setLatitude (location.getLatitude ()); LocationB.setLongitude (location.getLongitude ()); Location Location A = New Location ("Point A"); LocationA.setLatitude (prelat_val); Latin from pref location Asset langitid (prelong_val); // prol long (prelat_val & gt; 0.0 & amp; amp; amp; prelong_val & gt; 0.0) {toast. Make text (location service), "location odometer yoga" + odometer_sym, toast LNNHHL) Show (); Float distance2 = getDistance (prelat_val, prelong_val, location.getLatitude (), position.get langtid ()); Odometer_sm = odometer_sym + (distance2/1000); Toast. Maketext (location service, "wave" + prelate_val + "long" + prelang_val + "yoga" + odometer_sam, toast.lnnhH_LOG). Show (); } SaveData (lat, lng, odometer_sum); } Hold (exception e) {e.printStackTrace (); }} Public float getDistance (double D, double E, double F, double g) {float [] dist = new float [2]; Between location control (D, E, F, G, Dist); Return distance [0]; } This is the problem that we face here:
- This available location is not correct. When we test this app in 5 km distance, there is a difference of about 300-400 meters
- When the mobile is in the same place for a long time, it will always provide different latitudes and longitudes Does. If you check above the code snippet, in requestLocationUpdates (), we are setting the time interval of 30 seconds and 5 meters distance. Here's what we thought, if my mobile device runs at 5 meters distance and if it crosses the 30-second gap, then it will provide new latitude and longitude. But what really happens, despite the device movement provides every 30 seconds coordinates I'm not sure how to fix this problem.
- How to get the exact value, while the device is running Do I need to do more things in the code?
I'm actually trying many options. But I think I'm missing something here. Please help me on this. Thanks in advance ..
thanks
your minimum value in requestLocationUpdates (30 seconds) Is too long for the app trying to calculate the exact distance, I have used the locationManager.requestLocationUpdates (provider, 0, 5, locationListener); For a long time in my code and I get accurate updates, although this will drain the battery very fast, you have to try different values to strike the balance between the accuracy and battery life and see How is your app
Comments
Post a Comment