I want to develop a small app that calculates the distance while traveling. I have tried the solution below, based on the GPS of Android, but the result is wrong.
Please help me on this
My code:
locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 10, this);
public void onLocationChanged(Location location) {
if ((location != null)) {
if (location.getAccuracy()<50 && location.getSpeed()>0) {
onlocationChangeMethod(location);
lastlatitude = location.getLatitude();
lastlongitude = location.getLongitude();
}
}
}
public void onlocationChangeMethod(Location location){
if (lastlatitude > 0 ) {
float[] results = new float[5];
location.distanceBetween(location.getLatitude(), location.getLongitude(),
lastlatitude, lastlongitude, results);
}
}