Google Fit API 返回自行车活动的距离为空。

huangapple go评论54阅读模式
英文:

Google Fit API returns no distance for biking activity

问题

版本:

implementation "com.google.android.gms:play-services-fitness:21.1.0"

客户端定义:

GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestEmail()
    .requestScopes(Scope("https://www.googleapis.com/auth/fitness.activity.read"), Scope("https://www.googleapis.com/auth/fitness.location.read"))
    .requestIdToken(BuildConfig.GOOGLE_FIT_CLIENT_ID)
    .requestServerAuthCode(BuildConfig.GOOGLE_FIT_CLIENT_ID, true)
    .build()

val readRequest = DataReadRequest.Builder()
    .read(DataType.TYPE_ACTIVITY_SEGMENT)
    .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
    .build()

这会给我数据集列表 -> 数据点 -> 骑行活动,但没有距离数据,只有开始/结束时间和活动类型。

如果我在Google Fit应用中打开相同的活动,它会显示相同活动的距离。有什么想法吗?

英文:

Version:

implementation "com.google.android.gms:play-services-fitness:21.1.0"

Client definition:

GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .requestScopes(Scope("https://www.googleapis.com/auth/fitness.activity.read"), Scope("https://www.googleapis.com/auth/fitness.location.read"))
            .requestIdToken(BuildConfig.GOOGLE_FIT_CLIENT_ID)
            .requestServerAuthCode(BuildConfig.GOOGLE_FIT_CLIENT_ID, true)
            .build()

val readRequest = DataReadRequest.Builder()
                .read(DataType.TYPE_ACTIVITY_SEGMENT)
                .setTimeRange(startTime, endTime, TimeUnit.MILLISECONDS)
                .build()

This gives me the list of dataSets -> dataPoints -> biking activities but no data about the distance. Only start/end time and the activity type.

If I open same activity in Google Fit app, it shows the distance of same activities.
Any ideas?

答案1

得分: 1

在解析活动和位置之后,您需要在一个单独的查询中解析距离增量。

此数据类型捕获用户自上次读数以来移动的距离,以米为单位。在一个时间间隔内的总距离可以通过将该时间间隔内的所有值相加来计算。每个数据点的开始时间应表示覆盖距离的时间间隔的开始。开始时间必须等于或大于前一个数据点的结束时间。

https://developers.google.com/fit/datatypes/location#android_2
https://developers.google.com/fit/datatypes/location#distance_delta

英文:

After you parse activity and location, you need to parse distance delta in a separate query.

This data type captures distance travelled by the user since the last reading, in meters. The total distance over an interval can be calculated by adding together all the values during the interval. The start time of each data point should represent the start of the interval in which the distance was covered. The start time must be equal to or greater than the end time of the previous data point.

https://developers.google.com/fit/datatypes/location#android_2
https://developers.google.com/fit/datatypes/location#distance_delta

huangapple
  • 本文由 发表于 2023年6月22日 18:31:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76530971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定