Skip to main content
Version: v3

Distance

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

Distance Sensor.

info

permission code: data:user.hd.distance

Methods

getCurrent

Get the current distance

getCurrent(): number

onChange

Register the distance change event callback function

onChange(callback: () => void): void

offChange

Cancel the distance change event callback function

offChange(callback: () => void): void

Example

import { Distance } from '@zos/sensor'

const distance = new Distance()
const current = distance.getCurrent()
const callback = () => {
console.log(distance.getCurrent())
}

distance.onChange(callback)

// When not needed for use
distance.offChange(callback)