From 41599039bdb8c4f5b855fcc6157c4bb669f47fa3 Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Mon, 28 Oct 2024 18:39:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 5 +- pages_order/product/productDetail.vue | 6 +-- store/store.js | 15 ++++++ utils/position.js | 92 ++++++++++++++++++++--------------- 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/manifest.json b/manifest.json index 7f8b1a9..d8f75ea 100644 --- a/manifest.json +++ b/manifest.json @@ -58,14 +58,11 @@ }, "usingComponents" : true, "permission" : { - "scope.userLocation" : { - "desc" : "你的位置信息将用于小程序位置接口的效果展示" - }, "scope.userFuzzyLocation" : { "desc" : "你的位置信息将用于小程序位置接口的效果展示" } }, - "requiredPrivateInfos" : [ "chooseLocation", "getLocation" ] + "requiredPrivateInfos" : [ "chooseLocation", "getFuzzyLocation" ] }, "mp-alipay" : { "usingComponents" : true diff --git a/pages_order/product/productDetail.vue b/pages_order/product/productDetail.vue index 95ce01f..04f6261 100644 --- a/pages_order/product/productDetail.vue +++ b/pages_order/product/productDetail.vue @@ -37,10 +37,10 @@ - + diff --git a/store/store.js b/store/store.js index 80cbfa0..2f503a7 100644 --- a/store/store.js +++ b/store/store.js @@ -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({ diff --git a/utils/position.js b/utils/position.js index 744b95c..7d16230 100644 --- a/utils/position.js +++ b/utils/position.js @@ -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' + // }) + // } + // } + // }) }