构造函数 初始化定位SDK
初始化配置项
关闭
获取openid当前的位置
传入uuid、userid等唯一标识获取位置
返回定位信息或报错
// async/await
const result = await mallToLocation({
openid: 指定openid,
// userId: 指定userId,
// [key: string]: string
})
if (result.success) {
// ...code
} else {
// ...error
}
// Promise
mallToLocation('指定openid')
.then(result => // ...code)
.catch(e => // ...code)
监听惯性导航返回的位置结果,有两种模式: 定位SDK监听、手动传入位置监听
// SDK监听模式
mallToLocation.onPosition('openid')
// 因为惯导需要用到方向和动作传感器,必须先异步向浏览器授权
const auth = await mallToLocation.startInertialNavigation()
if (auth.success) {
mallToLocation.onInertialNavigation((type, data) => {
if (type === 'error') {
console.log('触发错误')
}
if (type === 'motion') {
console.log('触发惯导更新位置,返回位置')
} else if (type === 'orientation') {
console.log('触发方向更新,返回角度')
}
})
}
// 手动传入位置监听
监听openid的位置更新
传入uuid、userid等唯一标识获取位置
定位的配置项
更新后调用的函数
mallToLocation.onPosition(
{
openid: 指定openid,
// userId: 指定userId,
// [key: string]: string
},
{
openInertialNavigation: false, // 开启惯性导航 默认关闭
delay: 0, // 延迟n秒后开始获取位置, 默认0
interval: 1000, // 每隔n秒获取一次位置, 默认1000
delayStopTime: 10 * 1000, // 人物停止移动延迟停止位置更新时间 默认10秒
stopWalkingRefreshRange: 2 // 人物停止移动后位置更新的边界 默认2米
},
(res) => {
if (res.success) {
// ...code
}
}
)
手动设置经纬度位置用来配合惯导使用
开启惯导服务
停止惯导监听
停止位置更新监听
定位SDK基础类
const mallToLocation = new Location({ appId: '999', appSecret: 'testsecret', uuid: '1008' // inertialNavigationOptions: { // openWorker: false // } })