欢迎访问广西陌上网络科技有限责任公司官网 · 专注企业数字化管理软件定制开发 客服热线:黄生 15678982250

餐厨收运系统使用小程序定位

更新时间:2023-10-25 浏览:5782 标签:小程序 定位 

微信小程序定位有两种

1 大致定位,获取当前用户所在市是可以的,偏差可能有十几公里。无需其他主体类目认证

wx.getFuzzyLocation({

     type: 'wgs84',

     success (res) {

       console.log(res)

       var lnglat={lng:res.longitude,lat:res.latitude}

       that.getCity(lnglat)

       const latitude = res.latitude

       const longitude = res.longitude

     },

     fail(res)

     {

       console.log(res)

     }

    })

使用场景,数据列表仅需定位当前所在城市,显示该城市下的数据。例如下拉的市,县/区二级选择。或者数据以市级为界定传输到后台接口做筛选。


2 精确定位,持续实时获取当前定位,通过持续获取到的经纬度,判断当前骑手,司机所在位置,还可形成运动轨迹图展示。

startGetLocationByInterval:function () {

    var that = this

    wx.startLocationUpdateBackground({

      success(res) {

        console.log('开启后台定位', res)

      },

      fail(res) {

        console.log('开启后台定位失败', res)

      }

    })

    let index = 0

    wx.onLocationChange(function(res) {

      index += 2

      // 60秒上传1次经纬度

      if(index % 60 == 0){

        that.saveLocation(res.longitude,res.latitude)

      }

 

      if(index > 6000){

        index = 0

      }

    })

  }

0.087933s