第三方应用开发 客户端API JS-SDK 设备 地理位置
地理位置
最后更新:2020/07/27
可联系渠道经理采购或代理智慧硬件接口已支持设备 联系渠道经理
地理位置
最后更新:2020/07/27

目录

  • 使用企业微信内置地图查看位置接口
  • 获取地理位置接口
  • 打开持续定位接口
  • 停止持续定位接口
  • 监听地理位置变化
  • 使用企业微信内置地图查看位置接口

    wx.openLocation({
        latitude: 0, // 纬度,浮点数,范围为90 ~ -90
        longitude: 0, // 经度,浮点数,范围为180 ~ -180。
        name: '', // 位置名
        address: '', // 地址详情说明
        scale: 1, // 地图缩放级别,整形值,范围从1~28。默认为16
    });

    获取地理位置接口

    wx.getLocation({
        type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
        success: function (res) {
            var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
            var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
            var speed = res.speed; // 速度,以米/每秒计
            var accuracy = res.accuracy; // 位置精度
        }
    });
    企业微信App不支持speed参数,输出固定为0

    打开持续定位接口

    开始持续获取LBS信息

    wx.invoke('startAutoLBS',{
                        type: 'gcj02', // wgs84是gps坐标,gcj02是火星坐标
                    },
              function(res) {
                 if(res.err_msg == "startAutoLBS:ok"){
                    //调用成功
                 }else {
                    //错误处理
                }
              });
    此接口仅在企业微信2.4.20及以后版本支持。

    停止持续定位接口

    停止获取LBS信息

    wx.invoke('stopAutoLBS',{},
              function(res) {
                 if(res.err_msg == "stopAutoLBS:ok"){
                    //调用成功
                 }else {
                    //错误处理
                }
              });
    此接口仅在企业微信2.4.20及以后版本支持。

    监听地理位置变化

    用于监听地理位置的变化,前提是已经成功调用startAutoLBS。(注意:需提醒用户一直停留在当前页面)

    wx.onLocationChange( 
      function(res) {
        if(res.errMsg == "auto:location:report:ok"){
          var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
          var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
          var speed = res.speed; // 速度,以米/每秒计
          var accuracy = res.accuracy; // 位置精度
          var lbsIndex = 0;
        }else {
          //错误处理
        }
      }
    );
    此接口仅在企业微信2.4.20及以后版本支持。
    从3.0.26版本开始,当用户关闭了GPS时,接口返回的errMsg为 "auto:location:report:fail, gps closed."
    上一篇
    网络状态
    下一篇
    连接微信