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

1、先配置权限:

这是上图的代码:

        "permission": {  

            "scope.userLocation": {

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

            }

        }

第二步:写代码:

      
//====下面是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();
              }
            },
          });
        },
      });
    }
  },

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值