Skip to main content
版本:v3

getSportData

API_LEVEL 3.6 开始支持,API 兼容性请参考 API_LEVEL

获取运动实时数据。

信息

权限代码: data:user.hd.workout

类型

function getSportData(options: Options, callback: (callbackResult: CallbackResult) => void): Result

参数

Options

属性类型必填默认值说明API_LEVEL
typestring-运动类型,取值参考 SportType 的值3.6

CallbackResult

属性类型说明API_LEVEL
codenumber结果状态码,0 表示成功,非 0 表示失败3.6
datastring运动数据,返回值类型为字符串,需要使用 JSON.parse 进行解析,解析完的类型是 Array<object>object 具体类型参考下文 SportType 类型说明,每一种 type 对应的返回值都不同3.6

Result

类型说明
Boolean如果返回 true 说明调用成功,否则调用失败

SportType

类型说明API_LEVEL
speedobject速度,示例返回值 {"speed":"9.99", "name": "Speed"}3.6
avg_speedobject平均速度,示例返回值 {"avg_speed":"9.99", "name": "Average Speed"}3.6
paceobject配速,示例返回值 {"avg_pace":"1'12''", "name": "Average Pace"}3.6
avg_paceobject平均配速,示例返回值 {"avg_pace":"1'12''", "name": "Average Pace"}3.6
distanceobject距离,示例返回值 {"distance":"9.99", "name": "Distance"}3.6
durationobject运动用时,示例返回值 {"duration":"1:15:15", "name": "Duration"}3.6
caloriesobject消耗,示例返回值 {"calories":"9.99", "name": "Calories"}3.6
cadenceobject步频/踏频,示例返回值 {"cadence":"9.99", "name": "Cadence"}3.6
avg_cadenceobject平均步频/踏频,示例返回值 {"avg_cadence":"9.99", "name": "Average Cadence"}3.6
altitudeobject海拔,示例返回值 {"altitude":"9.99", "name": "Elevation"}3.6
total_up_altitudeobject累计上升海拔,示例返回值 {"total_up_altitude":"9.99", "name": "Total Ascent"}3.6
total_countobject总计数,示例返回值 {"total_count":"9.99", "name": "Total count"}3.6
vertical_speedobject垂直速度,示例返回值 {"vertical_speed":"9.99", "name": "Vertical Speed"}3.6
downhill_countobject滑降次数,示例返回值 {"downhill_count":"9.99", "name": "Downhills"}3.6
total_downhill_distanceobject累计滑降距离,示例返回值 {"total_downhill_distance":"9.99", "name": "Total Downhill Distance"}3.6

代码示例

import { getSportData } from '@zos/app-access'

const result = getSportData(
{
type: 'distance',
},
(callbackResult) => {
const { code, data } = callbackResult
if (code === 0) {
const [{ distance }] = JSON.parse(data)
console.log(distance)
}
},
)