diff --git a/pages/index/index.vue b/pages/index/index.vue index 121689f..c723839 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -85,10 +85,10 @@ isChecked: false }], isAllChecked: false, - // 打卡中心点经纬度 + // 打卡中心点经纬度 丽丰广场麦当劳 fenceCenter: { - latitude: 31.266909, - longitude: 120.633401 + latitude: 31.267166, + longitude: 120.632449 }, // 打卡点半径(单位:米) fenceRadius: 500 @@ -111,14 +111,10 @@ const coords = position.coords; console.log('纬度: ', coords.latitude); console.log('经度: ', coords.longitude); - console.log('高度: ', coords.altitude); - console.log('坐标精度: ', coords.accuracy); - console.log('高度精度: ', coords.altitudeAccuracy); - console.log('移动方向: ', coords.heading); - console.log('移动速度: ', coords.speed); const [gcj02Lng, gcj02Lat] = this.wgs84ToGcj02(coords.longitude, coords.latitude); console.log('转换后的 GCJ - 02 经度:', gcj02Lng); console.log('转换后的 GCJ - 02 纬度:', gcj02Lat); + console.log(this.isInsideFence(gcj02Lat, gcj02Lng)); }, (error) => { let locationStatus = '' @@ -136,7 +132,6 @@ locationStatus = '定位出现未知错误'; break; } - console.log(error) uni.showToast({ title: locationStatus, icon: 'none' @@ -144,7 +139,6 @@ } ); } else { - console.log('浏览器不支持地理定位功能') // 浏览器不支持地理定位 uni.showToast({ title: '浏览器不支持地理定位功能', @@ -152,6 +146,15 @@ }) } }, + isInsideFence(lat, lng) { + // 创建用户位置点和围栏中心点 + const userPoint = new qq.maps.LatLng(lat, lng); + const centerPoint = new qq.maps.LatLng(this.fenceCenter.latitude, this.fenceCenter.longitude); + // 计算用户位置与围栏中心点的距离 + const distance = qq.maps.geometry.spherical.computeDistanceBetween(userPoint, centerPoint); + console.log('用户位置与围栏中心点的距离',distance) + return distance <= this.fenceRadius; + }, // WGS84坐标转换为GCJ-02坐标 // 判断是否在中国范围内 outOfChina(lng, lat) { diff --git a/unpackage/dist/build/web/index.html b/unpackage/dist/build/web/index.html index cac3f58..982fea8 100644 --- a/unpackage/dist/build/web/index.html +++ b/unpackage/dist/build/web/index.html @@ -1,2 +1,2 @@