Browse Source

服务完成的高精度定位改为模糊定位

chenjj 2 days ago
parent
commit
d28f249627

+ 3 - 3
manifest.json

@@ -61,10 +61,10 @@
             "subPackages" : true
         },
         "lazyCodeLoading" : "requiredComponents",
-        "requiredPrivateInfos" : [ "chooseLocation","choosePoi","getLocation"],
+        "requiredPrivateInfos" : [ "chooseLocation","choosePoi","getFuzzyLocation"],
         "permission" : {
-            "scope.userLocation": {
-                "desc": "你的位置信息将用于小程序位"
+            "scope.userFuzzyLocation": {
+                "desc": "你的位置信息将用于小程序位置接口的效果展示"
             }
         },
         "mergeVirtualHostAttributes" : true

+ 0 - 3
pages.json

@@ -415,9 +415,6 @@
 	"plugins": {
 	},
 	"permission": {
-		"scope.userLocation": {
-			"desc": "你的位置信息将用于小程序定位"
-		},
 		"scope.userFuzzyLocation": {
 			"desc": "你的位置信息将用于小程序定位"
 		}

+ 60 - 54
pages_classify/pages/handle/index.vue

@@ -57,6 +57,8 @@ import Slide from '@/pages_classify/components/Slide/index.vue'
 import { useDict } from '@/utils/dict.js'
 import DictTag from '@/components/DictTag/index.vue'
 import { wxMakePhoneCall } from '@/utils/wxRequest.js'
+
+import { getLatLong } from '@/utils/adress'
 import { computed } from 'vue'
 const secondOrderId = ref('')
 const detaile = ref({})
@@ -79,33 +81,36 @@ const getCurrentLocation = () => {
     // 先检查用户是否授权了位置权限
     uni.getSetting({
       success: (res) => {
-        if (!res.authSetting['scope.userLocation']) {
-          // 如果用户未授权,先请求授权
-          uni.authorize({
-            scope: 'scope.userLocation',
-            success: () => {
-              // 授权成功后获取位置
-              getLocation(resolve, reject);
-            },
-            fail: (err) => {
-              console.error('位置授权失败:', err);
-              uni.showModal({
-                title: '提示',
-                content: '需要获取您的位置信息,请在设置中打开位置权限',
-                confirmText: '去设置',
-                success: (res) => {
-                  if (res.confirm) {
-                    uni.openSetting();
-                  }
-                }
-              });
-              reject(err);
-            }
-          });
-        } else {
-          // 已授权,直接获取位置
-          getLocation(resolve, reject);
-        }
+				console.log("TCL: getCurrentLocation -> res", res)
+        // 已授权,直接获取位置
+        getLocation(resolve, reject);
+        // if (!res.authSetting['scope.getFuzzyLocation']) {
+        //   // 如果用户未授权,先请求授权
+        //   uni.authorize({
+        //     scope: 'scope.getFuzzyLocation',
+        //     success: () => {
+        //       // 授权成功后获取位置
+        //       getLocation(resolve, reject);
+        //     },
+        //     fail: (err) => {
+        //       console.error('位置授权失败:', err);
+        //       uni.showModal({
+        //         title: '提示',
+        //         content: '需要获取您的位置信息,请在设置中打开位置权限',
+        //         confirmText: '去设置',
+        //         success: (res) => {
+        //           if (res.confirm) {
+        //             uni.openSetting();
+        //           }
+        //         }
+        //       });
+        //       reject(err);
+        //     }
+        //   });
+        // } else {
+        //   // 已授权,直接获取位置
+        //   getLocation(resolve, reject);
+        // }
       },
       fail: (err) => {
         console.error('获取设置失败:', err);
@@ -118,10 +123,10 @@ const getCurrentLocation = () => {
 // 获取位置的具体实现
 const getLocation = (resolve, reject) => {
   // 删除开发环境模拟位置的代码,始终获取真实位置
-  uni.getLocation({
+  uni.getFuzzyLocation({
     type: 'gcj02',
-    isHighAccuracy: true, // 高精度
-    highAccuracyExpireTime: 3000, // 高精度过期时间
+    // isHighAccuracy: true, // 高精度
+    // highAccuracyExpireTime: 3000, // 高精度过期时间
     success: (res) => {
       const { longitude, latitude } = res;
       console.log('当前位置 - 经度:', longitude);
@@ -211,12 +216,13 @@ const change = async (e) => {
       // })
       
       // 获取开始服务时的位置
-      const locationData = await getCurrentLocation().catch(err => {
-        // uni.hideLoading()
-        verify.value.initialization()
-        throw new Error('无法获取位置信息,请确保已开启位置权限')
-      })
-      
+      // const locationData = await getCurrentLocation().catch(err => {
+      //   // uni.hideLoading()
+      //   verify.value.initialization()
+      //   throw new Error('无法获取位置信息,请确保已开启位置权限')
+      // })
+    
+      const locationData =await getLatLong()
       // 构建参数字符串
       const params = `secondOrderId=${secondOrderId.value}&serviceStartLongitude=${locationData.longitude.toString()}&serviceStartLatitude=${locationData.latitude.toString()}`
       
@@ -250,7 +256,7 @@ const change = async (e) => {
       // uni.showLoading({
       //   title: '获取位置信息...'
       // })
-
+ 
       uni.showToast({
         title: '操作成功',
         icon: 'success',
@@ -279,23 +285,23 @@ onLoad((options) => {
   secondOrderId.value = options.secondOrderId
   getOrderDetail()
   
-  // 初始检查位置权限
-  getCurrentLocation().then(location => {
-    console.log('位置权限正常,可以获取位置');
-  }).catch(err => {
-    console.error('位置权限检查失败', err);
-    uni.showModal({
-      title: '位置权限提示',
-      content: '服务需要获取您的位置信息,请确保已开启位置权限',
-      confirmText: '去设置',
-      cancelText: '知道了',
-      success: (res) => {
-        if (res.confirm) {
-          uni.openSetting();
-        }
-      }
-    });
-  });
+  // // 初始检查位置权限
+  // getCurrentLocation().then(location => {
+  //   console.log('位置权限正常,可以获取位置');
+  // }).catch(err => {
+  //   console.error('位置权限检查失败', err);
+  //   uni.showModal({
+  //     title: '位置权限提示',
+  //     content: '服务需要获取您的位置信息,请确保已开启位置权限',
+  //     confirmText: '去设置',
+  //     cancelText: '知道了',
+  //     success: (res) => {
+  //       if (res.confirm) {
+  //         uni.openSetting();
+  //       }
+  //     }
+  //   });
+  // });
 })
 onUnload(() => {
   clearInterval(timer)

+ 10 - 9
pages_classify/pages/order/index.vue

@@ -88,6 +88,7 @@ import { getAddress } from '@/api/address.js'
 import { wxUploadFile, wxMakePhoneCall } from '@/utils/wxRequest.js'
 import { useDict } from '@/utils/dict.js';
 import DictTag from '@/components/DictTag/index.vue'
+import { getLatLong } from '@/utils/adress'
 const fileList = ref([]);
 const secondOrderId = ref('');
 const detaile = ref({
@@ -225,10 +226,10 @@ const getCurrentLocation = () => {
 // 获取位置的具体实现
 const getLocation = (resolve, reject) => {
 	// 删除开发环境模拟位置的代码,始终获取真实位置
-	uni.getLocation({
+	uni.getFuzzyLocation({
 		type: 'gcj02',
-		isHighAccuracy: true, // 高精度
-		highAccuracyExpireTime: 3000, // 高精度过期时间
+		// isHighAccuracy: true, // 高精度
+		// highAccuracyExpireTime: 3000, // 高精度过期时间
 		success: (res) => {
 			const { longitude, latitude } = res;
 			console.log('当前位置 - 经度:', longitude);
@@ -263,12 +264,12 @@ const onSubmit = async () => {
 	console.log('submit', fileList.value, img_urls);
 
 	// 获取结束服务时的位置
-	const locationData = await getCurrentLocation().catch(err => {
-		// uni.hideLoading()
-		verify.value.initialization()
-		throw new Error('无法获取位置信息,请确保已开启位置权限')
-	})
-
+	// const locationData = await getCurrentLocation().catch(err => {
+	// 	// uni.hideLoading()
+	// 	verify.value.initialization()
+	// 	throw new Error('无法获取位置信息,请确保已开启位置权限')
+	// })
+	const locationData =await getLatLong()
 	// 构建参数字符串
 	const params = `volunteerPicture=${img_urls}&volunteerReview=${detaile.value.volunteerReview}&secondOrderId=${secondOrderId.value}&serviceFinishLongitude=${locationData.longitude.toString()}&serviceFinishLatitude=${locationData.latitude.toString()}`
 

+ 2 - 2
pages_home/pages/Volunteerside/goodsDetails.vue

@@ -54,10 +54,10 @@
             </view>
 
             <!-- 右上角评分 -->
-            <view class="volunteer-rating">
+            <!-- <view class="volunteer-rating">
               <text class="rating-text">4.5</text>
               <text class="rating-label">评分</text>
-            </view>
+            </view> -->
           </view>
         </template>
       </up-card>

+ 22 - 1
utils/adress.js

@@ -121,6 +121,26 @@ function locateTheCurrentAddress(ad_array){
   })
 }
 
+function getLatLong(ad_array){
+  return new Promise((resolve, reject) => { 
+      wx.getFuzzyLocation({
+        type: 'gcj02',
+        success: function (res) {
+          const { latitude, longitude } =res;
+          resolve({
+            latitude, longitude
+          })
+          console.log('111', res,);
+
+        },
+        fail: function (res) {
+          console.log('fail', res);
+          reject();
+        }
+      })
+  })
+}
+
 function splitAddress(address) {
   // 处理直辖市(如北京市朝阳区)
   const directCityRegex = /^(北京|天津|上海|重庆)(市)?(.+?(区|县))/;
@@ -211,5 +231,6 @@ export {
   citySelectorNavigateTo,
   splitAddress,
   getCityCode,
-  locateTheCurrentAddress
+  locateTheCurrentAddress,
+  getLatLong
 }