Options
All
  • Public
  • Public/Protected
  • All
Menu

定位SDK基础类

const mallToLocation = new Location({
  appId: '999',
  appSecret: 'testsecret',
  uuid: '1008'
  // inertialNavigationOptions: {
  //   openWorker: false
  // }
})

Hierarchy

  • Location

Constructors

constructor

构造函数 初始化定位SDK

Parameters

Returns Location

Properties

Optional location

location: ILocationData

Methods

close

  • close(): void

关闭

Returns void

getPositionData

  • getPositionData(params: object, positionOptions?: undefined | object): Promise<ILocationResult>

获取openid当前的位置

Parameters

  • params: object

    传入uuid、userid等唯一标识获取位置

    • [key: string]: string
  • positionOptions: undefined | object Optional 

Returns Promise<ILocationResult>

返回定位信息或报错

// 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)

onInertialNavigation

  • onInertialNavigation(callback?: IInertialNavigationCallback): void

监听惯性导航返回的位置结果,有两种模式: 定位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('触发方向更新,返回角度')
      }
   })
 }
// 手动传入位置监听

Parameters

  • callback: IInertialNavigationCallback Optional 

Returns void

onPosition

  • onPosition(params: object, options?: ILocationOptions, callback: function): void

监听openid的位置更新

Parameters

  • params: object

    传入uuid、userid等唯一标识获取位置

    • [key: string]: string
  • options: ILocationOptions = {} Default value 

    定位的配置项

  • callback: function

    更新后调用的函数

    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
        }
      }
    )

Returns void

setPosition

  • setPosition(position: IPosition): undefined | object

手动设置经纬度位置用来配合惯导使用

Parameters

Returns undefined | object

startInertialNavigation

  • startInertialNavigation(): Promise<object>

开启惯导服务

Returns Promise<object>

stopInertialNavigation

  • stopInertialNavigation(): void

停止惯导监听

Returns void

stopPosition

  • stopPosition(): void

停止位置更新监听

Returns void

  • Inherited
  • Protected
  • Private
  • Static
  • Module
  • Object
  • Property
  • Function
  • Variable
  • Index
  • Type
  • Class
  • Interface
  • Enum
  • Constructor
  • Getter/Setter
Made with ❤️ by pirix-gh. Documentation generated by TypeDoc.