I have a problem with my GPS on Android (provider is set to GPS!) and I do not know how to tackle it.
I am working on a running track app. My current approach is to request location updates minTimesMs = 0, and minDistanceMeter = 10 meter.
requestLocationUpdates(LocationManager.GPS_PROVIDER, minTimeMs*1000, (float) minDistanceMeter, locationListener)
Then, I am putting the latitude and longitude coordinates into a list and calculate the distance between these points. As a second action I compare the provided speed and a predefined min-speed. If the delivered speed is greater than the min-speed (4.8), the distance between the last two recorded points will be calculated and summed up.
Now the problem is that my covered distance is adding up constantly although I have not moved that much.
Maybe, someone can tell me what else I should consider to get a better result of my covered path?
Side note: Accuracy is set to ACCURACY_FINE and ACCURACY_HIGH.
Here is my code
private void startLocationListener() {
locationListener = new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
//get the location name from latitude and longitude
latLng = new LatLng(latitude, longitude);
polylinePoints.add(latLng);
//get speed
speed = (location.getSpeed()/1000)*3600;
Log.d("SPEED", String.valueOf(location.getSpeed()));
//number of satellites
Log.d("NUMBER OF SATELLITES", String.valueOf(location.getExtras().getInt("satellites")));
}
};
}
private void calculateDistance() {
LatLng penultimatelastEntry = polylinePoints.get(polylinePoints.size()-2);
double startLat = penultimatelastEntry.latitude;
double startLng = penultimatelastEntry.longitude;
Double oldDoubleLat = startLat;
Double oldDoubleLng = startLng;
LatLng lastEntry = polylinePoints.get(polylinePoints.size()-1);
double newDoubleLat = lastEntry.latitude;
double newDoubleLng = lastEntry.longitude;
if(speed>minimumSpeedLimit) {
Location.distanceBetween(oldDoubleLat, oldDoubleLng, newDoubleLat, newDoubleLng, result);
calc += result[0];
saveToDatabase();
sendBroadcastToMapsActivity(polylinePoints);
}
}