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

  },
相关推荐
2501_9159184110 小时前
iOS 开发全流程实战 基于 uni-app 的 iOS 应用开发、打包、测试与上架流程详解
android·ios·小程序·https·uni-app·iphone·webview
黑马源码库miui5208610 小时前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·微信·微信小程序·小程序·uni-app
一口十个小甜虾11 小时前
微信小程序体验版,当打开调试模式正常访问,关闭之后无法访问
微信小程序·小程序
悟空码字11 小时前
微信开放平台第三方平台,可以管理多个微信小程序
微信·小程序·开放平台
じòぴé南冸じょうげん11 小时前
微信小程序如何进行分包处理?
前端·小程序
说私域13 小时前
基于开源AI大模型AI智能名片S2B2C商城小程序的参与感构建研究
人工智能·小程序·开源
毕设源码-邱学长1 天前
【开题答辩全过程】以 基于微信小程序的宠物领养系统为例,包含答辩的问题和答案
微信小程序·小程序·宠物
canglingyue1 天前
微信小程序日历事件添加实现
微信小程序·小程序
毕设源码-邱学长1 天前
【开题答辩全过程】以 基于微信小程序校园综合服务平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
從南走到北1 天前
JAVA同城打车小程序APP打车顺风车滴滴车跑腿源码微信小程序打车源码
java·开发语言·微信·微信小程序·小程序