欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

uniAPP微信小程序獲取當前地址 - 新聞資訊 - 云南小程序開發(fā)|云南軟件開發(fā)|云南網(wǎng)站建設-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設/小程序開發(fā)/軟件開發(fā)

知識

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!

您當前位置>首頁 » 新聞資訊 » 小程序相關 >

uniAPP微信小程序獲取當前地址

發(fā)表時間:2021-1-5

發(fā)布人:葵宇科技

瀏覽次數(shù):187

首先你要去配置一下你的app.json 如下:

	"permission": {
	  "scope.userLocation": {
	    "desc": "獲取你的位置信息...." 
	 }
	}

然后就可以你想在哪里展示就可以將代碼貼哪里了(這里推薦提出把這個地址寫成工具類獨立出來方便以后要用直接可以用)

<template>
	<view>
		<view class="positon-top">
			<view class="current-location">
				<text>我的位置</text>
				<image src="../../static/indexImg/address.png"/>:
			</view>
			<view class="address">{{Areaaddress}}</view>
		</view>
	</view>
</template>
<script>
	export default {
	   data() {
			return {
				Areaaddress:'' //當前位置
			}
		},
		mounted:function(){
			this.getAuthorizeInfo();
			this.getLocationInfo();
		},
		methods: {
			getAuthorizeInfo(a="scope.userLocation"){  //1. uniapp彈窗彈出獲取授權(地理,個人微信信息等授權信息)彈窗
				var _this=this;
				uni.authorize({
					scope: a,
					success() { //1.1 允許授權
						_this.getLocationInfo();
					},
					fail(){    //1.2 拒絕授權
						console.log("你拒絕了授權,無法獲得周邊信息")
					}
				})
			},
			getLocationInfo(){  //2. 獲取地理位置
				var _this=this;
				uni.getLocation({
					type: 'wgs84',
					success (res) {
					    console.log("你當前經(jīng)緯度是:");
						console.log(res)
						let latitude,longitude;
						latitude = res.latitude.toString();
						longitude = res.longitude.toString();
						uni.request({
							header:{
								"Content-Type": "application/text"
							},
							url:'http://apis.map.qq.com/ws/geocoder/v1/?location='+latitude+','+longitude+'&key=MVGBZ-R2U3U-W5CVY-2PQID-AT4VZ-PDF35',
							success(re) {
								console.log("中文位置")
								console.log(re)	   
								_this.Areaaddress  = re.data.result.address;
								if(re.statusCode === 200){
									console.log("獲取中文街道地理位置成功")
								}else{
									console.log("獲取信息失敗,請重試!")
								}
							 }
						});
					}
				});
			}
		}
	}
</script>

<style>
	 page{
		 font-size: 30upx;
		 font-family: "gray";
		 margin-top: 15upx;
		 margin-left: 20upx;
	 }
	 .current-location{
		width: 22%;
		height: 35upx;
		float: left;
		color: dimgray;
	 }
	 .address{
		 width: 69%;
		 height: 35upx;
		 float: left;
		 text-overflow: ellipsis; /* 顯示省略號 */
		 white-space: nowrap; /* 強制字體不換行 */
		 overflow: hidden; /* 隱藏 */
		 color: dimgray;
	 }
	 image{
		 height: 30upx;
		 width: 30upx;
	 }
</style>
上面代碼都確認無誤后,還出不來問題。

你去看看你的uniapp的 pages.json里面是否配置好定位配置。


再看看你的uniapp manifest.json里面的微信小程序定位功能是否開啟

在這里插入圖片描述

還有就是看看你的小程序配置好appid沒有和是否效驗了你的定位域名

在這里插入圖片描述
找到本地設置,勾選不校驗合法域名。(如果你在微信公眾平臺上配置好了你的服務器域名是https,這里你你可以直接忽略)。

在這里插入圖片描述

相關案例查看更多