Google Fit API : Get distance from google fit

前端 未结 5 879
小鲜肉
小鲜肉 2021-01-28 17:35

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         


        
5条回答
  •  北海茫月
    2021-01-28 18:10

    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;
            }
        }
    

提交回复
热议问题