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

  },
相关推荐
游戏开发爱好者820 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息1 天前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
光影少年2 天前
AIGC + Taro / 小程序
小程序·aigc·taro
2501_915918412 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
天空属于哈夫克32 天前
Go 语言实战:构建一个企微外部群“技术贴收藏夹”小程序后端
小程序·golang·企业微信
菜鸟una2 天前
【微信小程序+Taro 3+NutUI 3】input (nut-input) 、 textarea (nut-texteare)类型使用避坑
前端·vue.js·微信小程序·小程序·taro
计算机毕设指导62 天前
基于微信小程序的校园二手交易系统【源码文末联系】
java·spring boot·spring·微信小程序·小程序·tomcat·maven