最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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è)要用戶(hù)授權(quán)位置且可以用戶(hù)自己選擇位置的功能,需要的朋友可以參考下

使用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里添加微信用戶(hù)授權(quán)

onLaunch: function() {
	uni.authorize({
	  scope: 'scope.userLocation',
	  success: function () {
	    console.log('用戶(hù)同意了授權(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']) { /* 用戶(hù)授權(quán)成功時(shí)走這里 */
			        this.handerChooseLocation()
			      } else if (res.authSetting['scope.userLocation'] === undefined) { /* 用戶(hù)未授權(quán)時(shí)走這里 */
			        console.log('沒(méi)有授權(quán)')
			        this.handleOpenSetting()
			      } else { /* 用戶(hù)拒絕了授權(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)論

普安县| 天等县| 尼勒克县| 江城| 会泽县| 敖汉旗| 津南区| 韶山市| 河津市| 漠河县| 博爱县| 栾川县| 田林县| 荣昌县| 清水县| 南和县| 兴隆县| 清涧县| 比如县| 雷州市| 冷水江市| 民县| 孝感市| 东山县| 黑河市| 乐亭县| 定襄县| 隆安县| 寿阳县| 大新县| 石嘴山市| 延长县| 弥勒县| SHOW| 湘西| 成都市| 虹口区| 马鞍山市| 托克逊县| 来宾市| 紫阳县|