亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

uniapp使用uni.chooseLocation()打開(kāi)地圖選擇位置詳解

 更新時(shí)間:2023年06月30日 09:28:43   作者:哇,女前端哎!  
這篇文章主要給大家介紹了關(guān)于uniapp使用uni.chooseLocation()打開(kāi)地圖選擇位置的相關(guān)資料,因?yàn)樽罱陧?xiàng)目中遇到一個(gè)要用戶授權(quán)位置且可以用戶自己選擇位置的功能,需要的朋友可以參考下

使用uni.chooseLocation()打開(kāi)地址選擇位置

1、打開(kāi)微信開(kāi)發(fā)平臺(tái)申請(qǐng)權(quán)限

【開(kāi)發(fā)】–【開(kāi)發(fā)管理】–【接口設(shè)置】–點(diǎn)擊去開(kāi)通,開(kāi)通之后才可以使用。

2、對(duì)小程序進(jìn)行設(shè)置

“requiredPrivateInfos”:[“chooseLocation”]

1.第一種在 uniapp進(jìn)行設(shè)置

2.第二種在原生微信小程序上設(shè)置

3、在app.vue里添加微信用戶授權(quán)

onLaunch: function() {
	uni.authorize({
	  scope: 'scope.userLocation',
	  success: function () {
	    console.log('用戶同意了授權(quán)')
	  }
	})
},

4、在頁(yè)面調(diào)起地圖選擇

<template>
	<view class="content">
		<button @tap="authVerification">請(qǐng)選擇位置</button>
		<template v-if="currentLocation.address">
		  <div>name:{{currentLocation.name}}</div>
		  <div>address:{{currentLocation.address}}</div>
		  <div>latitude:{{currentLocation.latitude}}</div>
		  <div>longitude:{{currentLocation.longitude}}</div>
		</template>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				currentLocation:{},
			}
		},
		onShow () {
		  uni.getStorage({
		    key: 'currentLocation',
		    success: (res) => {
		      this.currentLocation = res.data
		    }
		  })
		},
		methods: {
			authVerification () {
			  uni.getSetting({
			    success: (res) => {
			      if (res.authSetting['scope.userLocation']) { /* 用戶授權(quán)成功時(shí)走這里 */
			        this.handerChooseLocation()
			      } else if (res.authSetting['scope.userLocation'] === undefined) { /* 用戶未授權(quán)時(shí)走這里 */
			        console.log('沒(méi)有授權(quán)')
			        this.handleOpenSetting()
			      } else { /* 用戶拒絕了授權(quán)后走這里 */
			        console.log('拒絕了授權(quán) false')
			        this.handleOpenSetting()
			      }
			    },
			  })
			},
			handerChooseLocation (latitude, longitude) {
			  uni.chooseLocation({
			    latitude: latitude || '',
			    longitude: longitude || '', 
			    success: (res) => {
			      console.log('wx.chooseLocation res=', res)
			      uni.setStorageSync('currentLocation', res)
			    },
			    fail: function (err) {
			      console.log('取消按鈕', err)
			    }
			  })
			},
			handleOpenSetting () {
			  wx.openSetting({
			    success: (res) => {
			      console.log('定位 openSetting', res)
			      if (res.authSetting["scope.userLocation"]) {
			        this.handerChooseLocation()
			      }
			    }
			  })
			}
		}
	}
</script>

總結(jié)

到此這篇關(guān)于uniapp使用uni.chooseLocation()打開(kāi)地圖選擇位置的文章就介紹到這了,更多相關(guān)uniapp打開(kāi)地圖選擇位置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論