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();
              }
            },
          });
        },
      });
    }
  },

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

相关推荐
weixin_462446231 小时前
ubuntu/kali安装k8s
linux·ubuntu·kubernetes
lys_8282 小时前
【linux】解决NAT模型下使用Xshell连接虚拟机显示22端口connection failed问题
linux·运维·服务器
序属秋秋秋3 小时前
《Linux系统编程之系统导论》【冯诺依曼体系结构 + 操作系统基本概述】
linux·运维·服务器·c语言·ubuntu·操作系统·冯诺依曼体系结构
她说彩礼65万4 小时前
C# 特性详解
linux·服务器·c#
Hi202402178 小时前
消除FFmpeg库的SONAME依赖
linux·ffmpeg
SelectDB9 小时前
Apache Doris 4.0.1 版本正式发布
数据库·apache
gfanbei10 小时前
ARM V8 Cortex R52 上电运行在什么状态?— Deepseek 解答
linux·arm开发·嵌入式硬件
liu****10 小时前
14.日志封装和线程池封装
linux·开发语言·c++
云动雨颤10 小时前
访问宝塔面板安全入口404?SSH命令轻松解决
linux·运维·安全
NPE~11 小时前
[Linux命令分享]日志查看 — — less
linux·运维·less·常用命令·日志查看