小程序使用经纬度通过腾讯位置服务、小程序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 () {
        // 成功或失败都会执行的回调
      }
    })

  },
相关推荐
低代码布道师9 小时前
加油站小程序实战教程10开通会员
前端·javascript·低代码·小程序
傻小胖9 小时前
UniApp 实现兼容 H5 和小程序的拖拽排序组件
小程序·uni-app
咕噜签名14 小时前
运行小程序需要选择什么配置的服务器
运维·服务器·小程序
玲子的猫17 小时前
微信小程序实现table样式,自带合并行合并列
微信小程序·小程序·notepad++
大叔_爱编程1 天前
wx212基于ssm+vue+uniapp的科创微应用平台小程序
vue.js·小程序·uni-app·毕业设计·ssm·课程设计·科创微应用平台小程序
2401_890666131 天前
免费送源码:Java+ssm+MySQL 校园二手书销售平台设计与实现 计算机毕业设计原创定制
java·spring boot·python·mysql·小程序·php·课程设计
Good Lucky1 天前
Skyline配置指南-微信小程序
chrome·微信小程序·小程序·skyline
code袁1 天前
基于微信小程序的校园跑腿系统的设计与实现
微信小程序·小程序·校园跑腿小程序·notepad++·小程序开发·校园跑腿小程序开发
27669582921 天前
哈喽打车 小程序 分析
小程序·哈喽打车·哈喽租车·哈喽·打车·小程序哈喽
Good Lucky2 天前
禁止页面滚动的方法-微信小程序
微信小程序·小程序