userID = "me"
dataTypeNameCalories = "com.google.calories.expended"
+ dataTypeNameDistance = "com.google.distance.delta"
dataTypeNameSteps = "com.google.step_count.delta"
dataTypeNameHeartrate = "com.google.heart_rate.summary"
)
Scopes: []string{
fitness.FitnessActivityWriteScope,
fitness.FitnessBodyWriteScope,
+ fitness.FitnessLocationWriteScope,
},
}
return nil
}
+func (c *Client) SetDistance(ctx context.Context, meters float64, startOfDay time.Time) error {
+ return c.updateCumulative(ctx,
+ &fitness.DataSource{
+ Application: Application(ctx),
+ DataType: &fitness.DataType{
+ Field: []*fitness.DataTypeField{
+ &fitness.DataTypeField{
+ Name: "distance",
+ Format: "floatPoint",
+ },
+ },
+ Name: dataTypeNameDistance,
+ },
+ Name: "Distance covered",
+ Type: "raw",
+ },
+ &fitness.Value{
+ FpVal: meters,
+ },
+ startOfDay)
+}
+
func (c *Client) SetSteps(ctx context.Context, totalSteps int, startOfDay time.Time) error {
return c.updateCumulative(ctx,
&fitness.DataSource{
return fmt.Errorf("gfitClient.SetCalories(%d) = %v", summary.Summary.CaloriesOut, err)
}
+ var distanceMeters float64
+ for _, d := range summary.Summary.Distances {
+ if d.Activity != "total" {
+ continue
+ }
+ distanceMeters = 1000.0 * d.Distance
+ break
+ }
+ if err := gfitClient.SetDistance(ctx, distanceMeters, tm); err != nil {
+ return fmt.Errorf("gfitClient.SetDistance(%d) = %v", distanceMeters, err)
+ }
+
if err := gfitClient.SetHeartRate(ctx, summary.Summary.HeartRateZones, summary.Summary.RestingHeartRate, tm); err != nil {
return fmt.Errorf("gfitClient.SetHeartRate() = %v", err)
}