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

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

相关推荐
学嵌入式的小杨同学5 小时前
从零打造 Linux 终端 MP3 播放器!用 C 语言实现音乐自由
linux·c语言·开发语言·前端·vscode·ci/cd·vim
EverydayJoy^v^5 小时前
RH134学习进程——十二.运行容器(1)
linux·运维·容器
syseptember6 小时前
Linux网络基础
linux·网络·arm开发
zl_dfq6 小时前
Linux 之 【多线程】(线程的概念、Linux中的线程、页表)
linux
郝亚军7 小时前
如何在Ubuntu和win10/11之间通过samba访问对方的文件
linux·服务器·ubuntu
曦云沐7 小时前
【避坑指南】Ubuntu更新报错“Repository is not signed”的快速修复
linux·ubuntu·docker
带土18 小时前
10. .out文件
linux
Exquisite.8 小时前
企业高性能web服务器(4)
运维·服务器·前端·网络·mysql
STCNXPARM8 小时前
Linux camera之V4L2子系统详解
android·linux·camera·v4l2架构
yueyuexiaokeai19 小时前
linux kernel常用函数整理
linux·c语言