小程序使用经纬度通过腾讯位置服务、小程序jdk、逆地址解析(位置描述)获取到详细信息

小程序后台



注册账户

控制台新建应用


配额

配额

下载jdk


下载

逆地址解析(位置描述)

javascript 复制代码
const QQMapWX = require('../../libs/qqmap-wx-jssdk.min.js');
javascript 复制代码
  getPosition() {
    console.log('getPosition');
    const that = this
    const qqmapsdk = new QQMapWX({
      key: 'JRKBZ-NVERJ-HCMF2-XCOR4-KQFBH-75FOO'
    });
    wx.getLocation({
      type: 'wgs84', // 默认为wgs84的GPS坐标,gcj02则返回可用于微信地图的坐标
      success: function (res) {
        const latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
        const longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
        const speed = res.speed; // 速度,以米/每秒计
        const accuracy = res.accuracy; // 位置精度
        console.log('当前位置纬度:' + latitude + ', 经度:' + longitude, speed, accuracy);

        qqmapsdk.reverseGeocoder({
          location: {
            latitude: latitude,
            longitude: longitude
          },
          success(res) {
            const address = res.result.address;
            console.log('详细地址:', address);
            that.setData({
              address: address
            })
          },
          fail(err) {
            console.error('逆地理编码失败', err);
          }
        });

        // 通过后端接口获取位置详细信息
        // request('', 'post', {
        //   latitude: latitude,
        //   longitude: longitude
        // }).then((res) => {
        //   console.log(res);
        //   if (res.msg === 'success') {
        //     that.setData({
        //       address: res
        //     })
        //   }
        // })
      },
      fail: function (err) {
        console.log('获取位置失败', err);
      },
      complete: function () {
        // 成功或失败都会执行的回调
      }
    })

  },
相关推荐
吴声子夜歌5 天前
小程序——布局示例
小程序
luffy54596 天前
微信小程序页面使用类似filter函数的wxs语法
微信小程序·小程序
Slow菜鸟6 天前
微信小程序开发(二)目录结构完全指南
微信小程序·小程序
小小王app小程序开发6 天前
海外盲盒小程序抽赏玩法分析(附跨境技术落地要点)
小程序
一叶星殇6 天前
微信小程序请求拦截器踩坑:避免重复刷新 token
微信小程序·小程序
hello kitty w6 天前
4. 基本语法
小程序
CHU7290356 天前
探索淘宝扭蛋机小程序:创意互动与趣味体验的融合
小程序
头发还在的女程序员6 天前
【免费下载】企业能源管理系统
小程序·策略模式·能源管理
吴声子夜歌6 天前
小程序——样式与布局
小程序
hello kitty w7 天前
3.小程序方法的封装
javascript·小程序