Procházet zdrojové kódy

地图距离问题,导航页地图缩小

yfape před 2 roky
rodič
revize
0e73559347
4 změnil soubory, kde provedl 22 přidání a 17 odebrání
  1. 1 1
      manifest.json
  2. 5 5
      pages/map/hotel-book/index.vue
  3. 1 1
      pages/map/map.vue
  4. 15 10
      utils/tools.js

+ 1 - 1
manifest.json

xqd
@@ -1,6 +1,6 @@
 {
     "name" : "hotel_uni",
-    "appid" : "__UNI__807A871",
+    "appid" : "__UNI__9140D70",
     "description" : "",
     "versionName" : "1.0.0",
     "versionCode" : "100",

+ 5 - 5
pages/map/hotel-book/index.vue

xqd xqd
@@ -111,9 +111,9 @@
 
 		onLoad(params) {
 			if(!this.$store.getters.userInfo){
-				uni.navigateTo({
+				uni.redirectTo({
 					url: '/pages/login/login'
-				})
+				})
 			}
 			if (params?.hotel_id) {
 				params.address = params.address == 'null' ? "" : params.address;
@@ -215,9 +215,9 @@
 					type: "gcj02",
 					latitude: parseFloat(this.hotel.latitude), // 纬度,浮点数,范围为90 ~ -90
 					longitude: parseFloat(this.hotel.longitude), // 经度,浮点数,范围为180 ~ -180。
-					scale: 6, // 地图缩放级别,整形值,范围从1~28。默认为最大
-				        name: this.hotel.name, // 位置名
-				        address: this.hotel.address, // 地址详情说明
+					scale: 12, // 地图缩放级别,整形值,范围从1~28。默认为最大
+					name: this.hotel.name, // 位置名
+					address: this.hotel.address, // 地址详情说明
 				})
 			}
 		}

+ 1 - 1
pages/map/map.vue

xqd
@@ -450,7 +450,7 @@
 						}
 					})
 					this.hotelList.map((item,index)=>{
-						item.distanceToMe=this.$utils.calcDistance(this.latitude,this.longitude,item.latitude,item.longitude).toFixed(1);
+						item.distanceToMe = this.$utils.calcDistance(this.geo.latitude,this.geo.longitude,item.latitude,item.longitude).toFixed(1);
 						return item;
 					})
 					this.$refs.map.updateContent(this.hotelList, true);

+ 15 - 10
utils/tools.js

xqd
@@ -174,16 +174,21 @@ const arrayDiff = function(arr1, arr2) {
 /**
  * 测试两个地理位置间得距离
  */
-const calcDistance = (lat1, lng1, lat2, lng2) => {
-	let radLat1 = lat1 * Math.PI / 180.0;
-	let radLat2 = lat2 * Math.PI / 180.0;
-	let a = radLat1 - radLat2;
-	let b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0;
-	let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + 
-	Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
-	s = s * 6378.137;
-	s = Math.round(s * 10000) / 10000;
-	return s;
+const calcDistance = (lat1,lng1,lat2,lng2)=>{
+	let radLat1 = Rad(lat1);
+	let radLat2 = Rad(lat2);
+	let a = radLat1 - radLat2;
+	let  b = Rad(lng1) - Rad(lng2);
+	let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) +
+	Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
+	s = s *6378.137 ;// EARTH_RADIUS;
+	s = Math.round(s * 10000) / 10000; //输出为公里
+	//s=s.toFixed(4);
+	return s;
+}
+
+const Rad = (d) => {
+    return d * Math.PI / 180.0;//经纬度转换成三角函数中度分表形式。
 }
 
 export default {