Uniapp中小程序调用腾讯地图(获取定位地址)

1、先配置权限:

这是上图的代码:

"permission": {

"scope.userLocation": {

"desc": "你的位置信息将用于小程序位置接口的效果展示"

}

}

第二步:写代码:

javascript 复制代码
      
//====下面是uniapp的模版代码 主要就是 chooseLocation  方法

<!-- 上门服务地址 -->
      <view class="form-item">
        <text class="label">
          <text class="required">*</text>上门服务地址
        </text>
        <view class="input-wrapper" @click="chooseLocation">
          <input class="input" placeholder="请定位" v-model="form.serviceAddr" />
        </view>
        <view v-if="showServiceAddrError" class="error-tip">*请填写上门服务地址</view>
      </view>

//====下面是script代码



    //微信定位
    chooseLocation() {
      uni.authorize({
        scope: 'scope.userLocation',
        success: () => {
          uni.chooseLocation({
            success: (res) => {
              this.form.serviceAddr = res.address || res.name;
            },
            fail: () => {
              uni.showToast({ title: '定位失败', icon: 'none' });
            },
          });
        },
        fail: () => {
          uni.showModal({
            title: '授权提示',
            content: '需要您授权地理位置权限',
            success: (modalRes) => {
              if (modalRes.confirm) {
                uni.openSetting();
              }
            },
          });
        },
      });
    }
  },

第三步:用不用去配置其他,就这样行就好了,可以调出来腾讯地图。

相关推荐
比奇堡派星星4 分钟前
Linux 杂项设备驱动框架详解
linux·arm开发·驱动开发
SeaTunnel14 分钟前
Apache SeaTunnel 2025 案例精选重磅发布!
大数据·开源·apache·seatunnel·案例
Eternity∞28 分钟前
基于Linux系统vim编译器情况下的C语言学习
linux·c语言·开发语言·学习·vim
芝麻馅汤圆儿36 分钟前
cpu 大小核
linux·运维·centos
m0_726965981 小时前
玩转(坏)服务器【一】
运维·服务器
牛奶咖啡131 小时前
shell脚本编程(三)
linux·shell脚本编程·环境变量的设置与取消·位置参数变量与内部参数变量·返回与退出状态·让变量获取键盘输入内容·使用decalre声明变量
2401_890443021 小时前
Linux进程间通信
linux·服务器
Xの哲學2 小时前
Linux 实时调度机制深度解析
linux·服务器·网络·算法·边缘计算
张太行_2 小时前
Linux信号处理函数中断流程分析
linux
晚风吹人醒.2 小时前
iptables防火墙规则(一):iptables语法结构,netfilter功能详解及案例演示
linux·服务器·网络·iptables·防火墙··netfilter