知識
不管是網(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,這里你你可以直接忽略)。
相關案例查看更多
相關閱讀
- 文山小程序開發(fā)
- 曲靖小程序開發(fā)
- uniapp開發(fā)小程序
- 云南網(wǎng)站建設首選
- painter
- 網(wǎng)站建設選
- 百度小程序公司
- 云南小程序設計
- 云南網(wǎng)站建設公司地址
- 云南網(wǎng)絡營銷顧問
- 微信分銷系統(tǒng)
- 汽車報廢回收管理系統(tǒng)
- 報廢車拆解系統(tǒng)
- 怎么做網(wǎng)站
- 云南建設廳網(wǎng)站
- 網(wǎng)站建設服務公司
- 開發(fā)制作小程序
- 電商網(wǎng)站建設
- 云南小程序制作
- 網(wǎng)站建設制作
- 霸屏推廣
- 網(wǎng)站優(yōu)化公司
- 云南微信小程序開發(fā)
- 小程序開發(fā)
- 云南網(wǎng)站建設方法
- 云南小程序開發(fā)報價
- 前端技術
- 小程序退款
- 網(wǎng)站建設費用
- 云南省住房建設廳網(wǎng)站