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

  },
相关推荐
不如摸鱼去8 小时前
Trae 辅助下的 uni-app 跨端小程序工程化开发实践分享
微信小程序·小程序·uni-app·aigc·ai编程
weixin_lynhgworld18 小时前
剧本杀小程序系统开发:构建剧本杀社交新生态
小程序
说私域18 小时前
基于定制开发开源 AI 智能名片 S2B2C 商城小程序的热点与人工下发策略研究
人工智能·小程序
weixin_lynhgworld18 小时前
陪诊小程序系统开发:让就医不再是一件难事
小程序
weixin_lynhgworld1 天前
盲盒抽谷机小程序系统开发:从0到1的完整方法论
小程序
weixin_lynhgworld2 天前
短剧小程序系统开发:赋能创作者,推动短剧艺术创新发展
小程序
一匹电信狗2 天前
【C++】异常详解(万字解读)
服务器·c++·算法·leetcode·小程序·stl·visual studio
说私域2 天前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务优化及复购转介绍提升策略研究
人工智能·小程序
熬耶3 天前
Uniapp之微信小程序自定义底部导航栏形态
微信小程序·小程序·uni-app
IT毕设实战小研3 天前
基于Spring Boot校园二手交易平台系统设计与实现 二手交易系统 交易平台小程序
java·数据库·vue.js·spring boot·后端·小程序·课程设计