简体中文
getLocation
约 264 字小于 1 分钟
2025-08-11
定位功能适配
参数
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| opts | Object | 是 | 配置选项对象 |
| opts.onSuccess | Function | 是 | 成功回调函数 |
| opts.onFail | Function | 是 | 失败回调函数 |
返回值
无返回值,通过回调函数返回结果。
成功回调参数 (onSuccess)
| 参数名 | 类型 | 说明 |
|---|---|---|
| errorCode | Number | 错误码,0 表示成功 |
| success | Boolean | 是否成功,true 表示成功 |
| address | String | 详细地址信息 |
| title | String | 位置标题(当前为空字符串) |
| longitude | Number | 经度 |
| latitude | Number | 纬度 |
| country | String | 国家(当前为空字符串) |
| province | String | 省份(当前为空字符串) |
| city | String | 城市(当前为空字符串) |
| district | String | 区县(当前为空字符串) |
失败回调参数 (onFail)
| 参数名 | 类型 | 说明 |
|---|---|---|
| error | String | 错误信息 |
使用示例
(function(root) {
root.jsapiAdapter = {
getLocation(opts) {
jsBridge.invokie('getLocation', {
onSuccess(res){
// 调用第三方APP原生的获取位置信息成功
opts.onSuccess({
errorCode: 0,
success: true,
address: res.address,
title: '',
longitude: res.long,
latitude: res.lant,
country: '',
province: '',
city: '',
district: ''
});
},
onFail() {
options.onFail('调用失败');
}
})
}
}
})jsBridge
第三方APP提供的原生桥接接口
