定位提示

main
lion 4 months ago
parent df170f5c34
commit 913becb570

@ -1,6 +1,6 @@
const mode = 'production'; //devLocal本地测试、devOnline线上测试、production生产环境 const mode = 'production'; //devLocal本地测试、devOnline线上测试、production生产环境
let ROOTPATH = 'https://h5.jscnsaas.cn'; let ROOTPATH = 'https://h5.jscnsaas.cn';
// let ROOTPATH = 'http://h5.ali251.langye.net'; // let ROOTPATH = 'https://vr.langye.net';
switch (mode) { switch (mode) {
case 'devLocal': case 'devLocal':
ROOTPATH = ROOTPATH ROOTPATH = ROOTPATH

@ -28,7 +28,7 @@
<map id="myMap" min-scale="6" max-scale="16" :longitude="lng" show-location :enable-scroll="!showLoad" <map id="myMap" min-scale="6" max-scale="16" :longitude="lng" show-location :enable-scroll="!showLoad"
@regionchange="pushMarkers" :scale="scale" :latitude="lat" :markers="markers" @callouttap="showDetail"> @regionchange="pushMarkers" :scale="scale" :latitude="lat" :markers="markers" @callouttap="showDetail">
<cover-view slot="callout" class="maps-covers"> <cover-view slot="callout" class="maps-covers">
<block v-for="(item,index) in markers"> <block v-for="(item,index) in markers" :key="item.id">
<cover-view :marker-id="item.id" :key='index'> <cover-view :marker-id="item.id" :key='index'>
<cover-view class="maps-cover"> <cover-view class="maps-cover">
<cover-view class="maps-cover-wrap"> <cover-view class="maps-cover-wrap">
@ -51,7 +51,7 @@
</block> </block>
</cover-view> </cover-view>
<cover-view class="maps-info" v-if="showNear"> <cover-view class="maps-info" v-if="showNear">
<cover-view class="maps-info-near" @click="getNears"> <cover-view class="maps-info-near" @click="getNears" v-if="!showLocationTip">
<cover-image src="../../static/home-near.png" mode=""></cover-image> <cover-image src="../../static/home-near.png" mode=""></cover-image>
</cover-view> </cover-view>
<cover-view class="maps-info-pointer" v-if="showPointer && pointer"> <cover-view class="maps-info-pointer" v-if="showPointer && pointer">
@ -63,7 +63,7 @@
</cover-view> </cover-view>
<cover-view>距你{{pointer.distance?pointer.distance:'-'}}</cover-view> <cover-view>距你{{pointer.distance?pointer.distance:'-'}}</cover-view>
<cover-view v-if="pointer.config.length>0"> <cover-view v-if="pointer.config.length>0">
<block v-for="con in pointer.config"> <block v-for="(con, cIdx) in pointer.config" :key="con.key || cIdx">
<block v-if="con.key==='address'"> <block v-if="con.key==='address'">
{{con.value}} {{con.value}}
</block> </block>
@ -82,6 +82,9 @@
</cover-view> </cover-view>
</cover-view> </cover-view>
</cover-view> </cover-view>
<cover-view class="maps-info-tip" v-if="showLocationTip" @click="retryLocationAuth">
使用完整功能需要获取您的定位点击授权
</cover-view>
</map> </map>
</view> </view>
@ -159,7 +162,8 @@
tips: '', tips: '',
showLoad: false, showLoad: false,
showNear: true, showNear: true,
showLabel:false showLabel:false,
showLocationTip: false
} }
}, },
@ -170,12 +174,7 @@
return shareInfo return shareInfo
}, },
onReady() { onReady() {
uni.authorize({ this.initLocationAuth()
scope: 'scope.userLocation',
success: (res) => {
this.getUserLocation()
}
})
this.mapContext = uni.createMapContext('myMap', this); this.mapContext = uni.createMapContext('myMap', this);
// //
let _this = this let _this = this
@ -249,11 +248,41 @@
}, },
methods: { methods: {
initLocationAuth() {
uni.getSetting({
success: (res) => {
const setting = res.authSetting || {}
const loc = setting['scope.userLocation']
if (loc === true) {
this.showLocationTip = false
this.getUserLocation()
} else if (loc === false) {
this.showLocationTip = true
} else {
// undefined: first time, try authorize
uni.authorize({
scope: 'scope.userLocation',
success: () => {
this.showLocationTip = false
this.getUserLocation()
},
fail: () => {
this.showLocationTip = true
}
})
}
},
fail: () => {
this.showLocationTip = true
}
})
},
// //
getUserLocation() { getUserLocation() {
uni.getLocation({ uni.getLocation({
type: 'gcj02', type: 'gcj02',
success: (res) => { success: (res) => {
this.showLocationTip = false
uni.removeStorageSync('vuex_latlng') uni.removeStorageSync('vuex_latlng')
this.lng = res.longitude this.lng = res.longitude
this.lat = res.latitude this.lat = res.latitude
@ -265,6 +294,47 @@
}, },
fail: (err) => { fail: (err) => {
console.log("err", err) console.log("err", err)
this.showLocationTip = true
}
})
},
retryLocationAuth() {
// authorize
uni.getSetting({
success: (res) => {
const setting = res.authSetting || {}
const loc = setting['scope.userLocation']
if (loc === true) {
this.showLocationTip = false
this.getUserLocation()
} else if (loc === false) {
uni.openSetting({
success: (rs) => {
if (rs.authSetting && rs.authSetting['scope.userLocation']) {
this.showLocationTip = false
this.getUserLocation()
}
}
})
} else {
uni.authorize({
scope: 'scope.userLocation',
success: () => {
this.showLocationTip = false
this.getUserLocation()
},
fail: () => {
uni.openSetting({
success: (rs) => {
if (rs.authSetting && rs.authSetting['scope.userLocation']) {
this.showLocationTip = false
this.getUserLocation()
}
}
})
}
})
}
} }
}) })
}, },
@ -668,6 +738,20 @@
display: inline-block; display: inline-block;
} }
} }
&-tip {
position: absolute;
left: 50%;
bottom: 160rpx;
transform: translate(-50%,-50%);
width: 80%;
z-index: 99;
text-align: center;
background: rgba(0,0,0,0.6);
color: #fff;
padding: 10rpx 30rpx;
border-radius: 40rpx;
}
} }

Loading…
Cancel
Save