How do I calculate the distance covered by the user using the google fit API? Currently I am using google Fit History Api like this :
DataReadRequest readRequest
To get distance covered by user, use below code and let me know if any further assistance required. The below code will get current day distance. To get distance for more days we can get list of activities from where we can get distance of more days.
private double getTodayDistance() {
PendingResult result = Fitness.HistoryApi.readDailyTotal(mClient, DataType.TYPE_DISTANCE_DELTA);
DailyTotalResult totalResult = result.await(1, TimeUnit.DAYS);
if (totalResult.getStatus().isSuccess()) {
DataSet totalSet = totalResult.getTotal();
if (totalSet != null && !totalSet.isEmpty()) {
return baseActivity.getMiles((totalSet.getDataPoints().get(0).getValue(Field.FIELD_DISTANCE)).asFloat());
} else {
android.util.Log.w(TAG, "There was a problem getting the calories.");
return 0;
}
} else {
return 0;
}
}