Browse Source

上传

master
前端-胡立永 4 months ago
parent
commit
41599039bd
4 changed files with 71 additions and 47 deletions
  1. +1
    -4
      manifest.json
  2. +3
    -3
      pages_order/product/productDetail.vue
  3. +15
    -0
      store/store.js
  4. +52
    -40
      utils/position.js

+ 1
- 4
manifest.json View File

@ -58,14 +58,11 @@
},
"usingComponents" : true,
"permission" : {
"scope.userLocation" : {
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
},
"scope.userFuzzyLocation" : {
"desc" : "你的位置信息将用于小程序位置接口的效果展示"
}
},
"requiredPrivateInfos" : [ "chooseLocation", "getLocation" ]
"requiredPrivateInfos" : [ "chooseLocation", "getFuzzyLocation" ]
},
"mp-alipay" : {
"usingComponents" : true


+ 3
- 3
pages_order/product/productDetail.vue View File

@ -37,10 +37,10 @@
</view>
<view class="info-unit">
<uv-cell title="是否有桌布" isLink
@click="$utils.navigateTo('/pages_order/mine/lease?type=add')">
<uv-cell title="您有物品吗?" isLink
@click="$refs.submitUnitSelect.open('bottom')">
<template #icon>
<text class="text">桌布</text>
<text class="text">物品</text>
</template>
</uv-cell>


+ 15
- 0
store/store.js View File

@ -155,6 +155,21 @@ const store = new Vuex.Store({
console.log(res);
state.position = res
})
// console.log('wx.getFuzzyLocation');
// uni.getFuzzyLocation({
// type: 'wgs84',
// isHighAccuracy: true,
// highAccuracyExpireTime: 1000,
// success (res) {
// const latitude = res.latitude
// const longitude = res.longitude
// state.position = {
// latitude,
// longitude
// }
// console.log(res);
// }
// })
},
logout(state){
uni.showModal({


+ 52
- 40
utils/position.js View File

@ -26,18 +26,25 @@ function calculateDistance(lat1, lon1, lat2, lon2) { //计算两点距离
function getLocation(fn) { //获取用户经纬度
wxGetLocation() //此方法只用于提示用户打开gps
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
highAccuracyExpireTime: 1000,
success: function(position) {
fn(position)
},
fail: function() { //使用ip获取定位
let key = config.mapKey; //腾讯地图key
getUserAddressByIp(key).then(res => {
fn(res.position) //返回经纬度
})
// uni.getLocation({
// type: 'gcj02',
// isHighAccuracy: true,
// highAccuracyExpireTime: 1000,
// success: function(position) {
// fn(position)
// },
// fail: function() { //使用ip获取定位
// let key = config.mapKey; //腾讯地图key
// getUserAddressByIp(key).then(res => {
// fn(res.position) //返回经纬度
// })
// }
// })
uni.getFuzzyLocation({
type: 'wgs84',
success (res) {
fn(res)
}
})
}
@ -46,20 +53,25 @@ function getLocationDetail() { //获取用户详细地址
wxGetLocation()
return new Promise((resolve, reject) => {
let key = config.mapKey; //腾讯地图key
uni.getLocation({
type: 'gcj02',
isHighAccuracy: true,
highAccuracyExpireTime: 1000,
success: function(position) {
getUserAddress(position.latitude, position.longitude, key).then(res => {
resolve(res)
})
},
fail: function() { //使用ip获取定位
getUserAddressByIp(key).then(res => {
resolve(res)
})
}
// uni.getLocation({
// type: 'gcj02',
// isHighAccuracy: true,
// highAccuracyExpireTime: 1000,
// success: function(position) {
// getUserAddress(position.latitude, position.longitude, key).then(res => {
// resolve(res)
// })
// },
// fail: function() { //使用ip获取定位
// getUserAddressByIp(key).then(res => {
// resolve(res)
// })
// }
// })
getLocation((position) => {
getUserAddress(position.latitude, position.longitude, key).then(res => {
resolve(res)
})
})
})
}
@ -151,20 +163,20 @@ function wxGetLocation(successCallback, failCallback) {
// #endif
console.log('wx.getLocation');
wx.getLocation({
type: 'gcj02',
isHighAccuracy: true,
highAccuracyExpireTime: 2000,
success(res) {},
fail(err) {
if(err.errMsg == 'getLocation:gps closed'){
uni.showToast({
title: '请打开GPS定位,否则定位不准确',
icon: 'none'
})
}
}
})
// wx.getLocation({
// type: 'gcj02',
// isHighAccuracy: true,
// highAccuracyExpireTime: 2000,
// success(res) {},
// fail(err) {
// if(err.errMsg == 'getLocation:gps closed'){
// uni.showToast({
// title: '请打开GPS定位,否则定位不准确',
// icon: 'none'
// })
// }
// }
// })
}


Loading…
Cancel
Save