uni.onLocationChange(callback)
监听实时地理位置变化事件,需结合 uni.startLocationUpdate 或 uni.startLocationUpdateBackground 使用。
onLocationChange 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
OnLocationChangeCallbackResult 的属性值
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
latitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 纬度,范围为 -90~90,负数表示南纬 |
longitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 经度,范围为 -180~180,负数表示西经 |
accuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 位置的精确度 |
altitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 高度,单位 m |
altitudeAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 高度的精确度 |
speed | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 速度,单位 m/s |
horizontalAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 水平精度,单位 m |
verticalAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 垂直精度,单位 m(Android 无法获取,返回 0) |
返回值
参见
uni.offLocationChange(callback)
关闭监听实时位置变化,前后台都停止消息接收。
offLocationChange 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
OffLocationChangeCallbackResult 的属性值
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
latitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 纬度,范围为 -90~90,负数表示南纬 |
longitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 经度,范围为 -180~180,负数表示西经 |
accuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 位置的精确度 |
altitude | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 高度,单位 m |
altitudeAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 高度的精确度 |
speed | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 速度,单位 m/s |
horizontalAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 水平精度,单位 m |
verticalAccuracy | number | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 垂直精度,单位 m(Android 无法获取,返回 0) |
返回值
参见
uni.onLocationChangeError(callback)
监听持续定位接口返回失败时触发。
onLocationChangeError 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
callback | (result: any) => void | 是 | - | - | - |
返回值
参见
uni.offLocationChangeError(callback)
取消注册位置更新错误回调。
offLocationChangeError 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
callback | (result: any) => void | 是 | - | - | - |
返回值
参见
uni.startLocationUpdate(options)
开启小程序进入前台时接收位置消息。
startLocationUpdate 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
options | StartLocationUpdateOptions | 是 | - | - | - |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | type | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 指定坐标系类型,可以是 wgs84 或 gcj02 | success | (result: StartLocationUpdateSuccess) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 接口调用成功的回调函数 | fail | (result: UniError) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 接口调用失败的回调函数 | complete | (result: any) => void | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 接口调用结束的回调函数(调用成功、失败都会执行) |
|
StartLocationUpdateSuccess 的属性值
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
name | string | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 位置名称 |
address | string | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 详细地址 |
latitude | number | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 纬度,浮点数,范围为-90~90,负数表示南纬 |
longitude | number | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 经度,范围为-180~180,负数表示西经 |
errMsg | string | 否 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 错误信息
|
返回值
参见
uni.stopLocationUpdate(options)
关闭监听实时位置变化,前后台都停止消息接收。
stopLocationUpdate 兼容性
Web | 微信小程序 | Android | iOS |
x | 4.41 | x | x |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
options | any | 是 | - | - | - |
返回值
参见
uni.startLocationUpdateBackground(option)
通用类型
GeneralCallbackResult
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 |
errMsg | string | 是 | - |
Web
|
微信小程序
|
Android
|
iOS
| - | 4.41 | - | - |
| 错误信息 |