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();}},});},});}},
第三步:用不用去配置其他,就這樣行就好了,可以調出來騰訊地圖。