diff --git a/index.html b/index.html
index c13c0de..5864413 100644
--- a/index.html
+++ b/index.html
@@ -2,6 +2,7 @@
+
苏州市导游协会
-
-
diff --git a/manifest.json b/manifest.json
index 47395eb..d4cfc65 100644
--- a/manifest.json
+++ b/manifest.json
@@ -98,8 +98,10 @@
"qqmap" : {
"key" : "4QQBZ-35LWQ-7725U-45ZGA-MIB5E-ZXBEA"
},
- "tencent" : {
- "key" : "XCJBZ-XJVL5-JCYID-IYEOP-AM7I2-2CF7E"
+ "amap" : {
+ "key" : "94570d4c90f67403af4f7ecc0e7fc136",
+ "securityJsCode" : "b8bc46fc1358ec6a16e8236518ffbdc9",
+ "serviceHost" : ""
}
}
}
diff --git a/pages/index/index.vue b/pages/index/index.vue
index c723839..e7b901b 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -85,13 +85,21 @@
isChecked: false
}],
isAllChecked: false,
- // 打卡中心点经纬度 丽丰广场麦当劳
- fenceCenter: {
- latitude: 31.267166,
- longitude: 120.632449
- },
+ // 打卡中心点经纬度
+ fenceCenter: [
+ {latitude: 31.267166, longitude: 120.632449}, // 丽丰广场麦当劳
+ {latitude: 31.266902, longitude: 120.630162}, //
+ {latitude: 31.266841, longitude: 120.628526},
+ {latitude: 31.26576, longitude: 120.629256}
+ ],
+ // 最近的打卡点索引
+ nearestFenceIndex: null,
// 打卡点半径(单位:米)
- fenceRadius: 500
+ fenceRadius: 500,
+ // 用户与打卡坐标的距离
+ distance: null,
+ // 用于存储 watchPosition 的返回值,方便后续清除监听
+ watchId: null
}
},
onLoad() {
@@ -99,22 +107,38 @@
this.getList()
},
onShow() {
- this.checkLocation()
+ // 开始监听用户位置
+ this.watchLocation()
+ },
+ onHide() {
+ // 页面隐藏时清除位置监听
+ if (this.watchId) {
+ navigator.geolocation.clearWatch(this.watchId)
+ }
},
methods: {
- // 检查用户是否已经授权定位权限
- checkLocation() {
+ // 监听用户位置变化
+ watchLocation() {
if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(
+ this.watchId = navigator.geolocation.watchPosition(
(position) => {
- // 获取到定位信息说明浏览器支持定位
const coords = position.coords;
- console.log('纬度: ', coords.latitude);
- console.log('经度: ', coords.longitude);
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));
+ // 计算用户与每个打卡点的距离,找出最近的打卡点
+ let minDistance = Infinity;
+ let nearestIndex = null;
+ this.fenceCenter.forEach(i => {
+ const distance = this.calculateDistance(item.latitude,item.longitude, gcj02Lat, gcj02Lng)
+ console.log(distance)
+ if (distance < minDistance) {
+ minDistance = distance;
+ nearestIndex = index;
+ }
+ })
+ this.distance = minDistance;
+ this.nearestFenceIndex = nearestIndex;
+ console.log('用户与最近打卡点之间的距离',this.distance)
+ console.log('最近的打卡点索引', this.nearestFenceIndex);
},
(error) => {
let locationStatus = ''
@@ -146,15 +170,6 @@
})
}
},
- 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/static/js/CommonFunction.js b/static/js/CommonFunction.js
index 7b9045c..68291ab 100644
--- a/static/js/CommonFunction.js
+++ b/static/js/CommonFunction.js
@@ -167,6 +167,22 @@ Vue.prototype.ShowDateDay = day => {
}
// 手机号显示加密
-Vue.prototype.encryptPhone = (phone) =>{
+Vue.prototype.encryptPhone = (phone) => {
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
+}
+
+// 计算两个经纬度间的距离
+Vue.prototype.calculateDistance = (lat1, lon1, lat2, lon2) => {
+ const R = 6371e3; // 地球半径,单位:米
+ const φ1 = lat1 * (Math.PI / 180);
+ const φ2 = lat2 * (Math.PI / 180);
+ const Δφ = (lat2 - lat1) * (Math.PI / 180);
+ const Δλ = (lon2 - lon1) * (Math.PI / 180);
+
+ const a = Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
+ Math.cos(φ1) * Math.cos(φ2) *
+ Math.sin(Δλ / 2) * Math.sin(Δλ / 2);
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+
+ return R * c;
}
\ No newline at end of file
diff --git a/unpackage/dist/build/web/index.html b/unpackage/dist/build/web/index.html
index 982fea8..ef92bff 100644
--- a/unpackage/dist/build/web/index.html
+++ b/unpackage/dist/build/web/index.html
@@ -1,2 +1,2 @@
daoyou
\ No newline at end of file
+ document.write('')