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

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

相关推荐
lpfasd1232 小时前
第2部分:Netty核心架构与原理解析
运维·服务器·架构
若尘拂风2 小时前
centos 7.9 编译安装 freeswitch 1.10.12
服务器·udp·freeswitch·sip
小蜜蜂爱编程2 小时前
gerrit的部署与配置关联到不同服务器上的git仓库
运维·服务器·git·gerrit
-指短琴长-2 小时前
Namespace隔离实战【Linux】
linux
心灵宝贝3 小时前
申威(sw_64)架构下如何安装java-1.8.0-swjdk的rpm包?
linux·运维·服务器
好记忆不如烂笔头abc3 小时前
linux系统记录登录用户的所有操作
java·linux·服务器
远向光3 小时前
k8s中的控制器
linux·容器·kubernetes
tan180°3 小时前
Linux网络HTTP(中)(8)
linux·网络·http
野犬寒鸦3 小时前
从零起步学习MySQL || 第五章:select语句的执行过程是怎么样的?(结合源码深度解析)
java·服务器·数据库·后端·mysql·adb
半梦半醒*4 小时前
搭建Jenkins
linux·运维·centos·tomcat·jenkins·运维开发