I'm trying to develop a Simple Application which calculates the travel distance based on current Latitude and longitude.
The basic problem i'm having is that sometimes the new Latitude and Longitude are far away than 3 - 2000 km.
is there any thing which i'm doing wrong? please advice
Here is what i'm doing...
protected void startLocationUpdates() {
if (mGoogleApiClient != null) {
if (mGoogleApiClient.isConnected()) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission
.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ActivityCompat
.checkSelfPermission(this, Manifest.permission
.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[]
// permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the
// documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}
} else {
buildGoogleApiClient();
}
}
@Override
public void onLocationChanged(Location location) {
if(oldLocation!=null)}{
double oldLatitude = oldLocation.getLatitude();
double oldLongitude = oldLocation.getLongitude();
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
float[] f = new float[1];
Location.distanceBetween(oldLatitude, oldLongitude, currentLatitude
currentLongitude, f);
}