欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > Uniapp中小程序调用腾讯地图(获取定位地址)

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

2025/5/18 13:32:43 来源:https://blog.csdn.net/liuruiaaa/article/details/147991062  浏览:    关键词: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();}},});},});}},

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

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词