From c64b1e69da3a72bd9cfd9d725fb812489c904199 Mon Sep 17 00:00:00 2001
From: 董国庆 <364620639@qq.com>
Date: 星期四, 13 三月 2025 14:40:43 +0800
Subject: [PATCH] Merge branch 'master' of http://120.76.84.145:10101/gitblit/r/H5/threeSide

---
 H5/pages/location/location.vue |  101 ++++++++++++++++++--------------------------------
 1 files changed, 36 insertions(+), 65 deletions(-)

diff --git a/H5/pages/location/location.vue b/H5/pages/location/location.vue
index 3450a55..d4c5c79 100644
--- a/H5/pages/location/location.vue
+++ b/H5/pages/location/location.vue
@@ -50,6 +50,7 @@
 			};
 		},
 		methods: {
+
 			clearMarkers() {
 				// 清除所有标点
 				this.markers.forEach((marker) => {
@@ -99,35 +100,6 @@
 
 					}
 				})
-				return
-				uni.request({
-					url: `https://api.map.baidu.com/place/v2/search`,
-					method: 'GET',
-					data: {
-						query: this.keyword,
-						location: `${this.latitude},${this.longitude }`,
-						radius: 10000, // 搜索半径,单位:米
-						output: 'json',
-						ak: '3mHKIXMArjgIkgADzOlTYp4XssNSNkwr' // 替换为你自己的 AK
-					},
-					success: (res) => {
-
-						if (res.data.status === 0) {
-							this.searchResults = res.data.results;
-							this.latitude = res.data.results[0].location.lat
-							this.longitude = res.data.results[0].location.lng
-							this.locationList = res.data.results.map((result, index) => {
-
-								result.id = index + 1
-
-								return result
-							});
-						}
-					},
-					fail: (err) => {
-						console.error('搜索失败:', err);
-					}
-				});
 			},
 		},
 		onLoad() {
@@ -136,34 +108,34 @@
 		onReady() {
 			this.map = new BMapGL.Map("container"); // 创建地图实例 
 			const that = this
-			// uni.getLocation({
-			// 	type: 'wgs84',
-			// 	success: (res) => {
 			navigator.geolocation.getCurrentPosition(success, error, options);
 
 			function success(position) {
-				const latitude = position.coords.latitude;
-				const longitude = position.coords.longitude;
-				const accuracy = position.coords.accuracy; // 精度,单位米
-				//  在这里可以使用获取到的经纬度信息,例如在地图上显示位置等。
-				var point = new BMapGL.Point(longitude, latitude); // 创建点坐标
-				that.map.enableScrollWheelZoom(true);
-				that.map.centerAndZoom(point, 12);
-				var marker = new BMapGL.Marker(point);
-				that.map.addOverlay(marker);
-				that.markers.push(marker);
-				var myGeo = new BMapGL.Geocoder();
-				// 根据坐标得到地址描述    
-				myGeo.getLocation(new BMapGL.Point(longitude, latitude), (result) => {
-					that.locationList = result.surroundingPois.map((item, index) => {
-						item.id = index + 1
-						return item
-					})
-				})
+				uni.request({
+					url: `https://api.map.baidu.com/geoconv/v2/?coords=${position.coords.longitude},${position.coords.latitude}&model=2&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`,
+					method: 'GET',
+					success: (res) => {
+						const latitude = res.data.result[0].y;
+						const longitude = res.data.result[0].x;
+						var point = new BMapGL.Point(longitude, latitude); // 创建点坐标
+						that.map.enableScrollWheelZoom(true);
+						that.map.centerAndZoom(point, 12);
+						var marker = new BMapGL.Marker(point);
+						that.map.addOverlay(marker);
+						that.markers.push(marker);
+						var myGeo = new BMapGL.Geocoder();
+						// 根据坐标得到地址描述    
+						myGeo.getLocation(new BMapGL.Point(longitude, latitude), (result) => {
+							that.locationList = result.surroundingPois.map((item, index) => {
+								item.id = index + 1
+								return item
+							})
+						})
+					},
+				});
 			}
 
 			function error(err) {
-
 				switch (err.code) {
 					case err.PERMISSION_DENIED:
 						console.error("用户拒绝了位置请求。");
@@ -184,6 +156,7 @@
 				timeout: 5000, // 5 秒超时
 				maximumAge: 0 //  不使用缓存
 			};
+
 			this.map.addEventListener('click', (e) => {
 				this.clearMarkers()
 				var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat);
@@ -194,31 +167,29 @@
 				var myGeo = new BMapGL.Geocoder();
 				// 根据坐标得到地址描述    
 				myGeo.getLocation(new BMapGL.Point(e.latlng.lng, e.latlng.lat), (result) => {
-					console.log(result,'result');
-					if( result.surroundingPois.length>0){
+					this.city = result.addressComponents.city
+					if (result.surroundingPois.length > 0) {
 						this.locationList = result.surroundingPois.map((item, index) => {
 							item.id = index + 1
 							return item
 						})
-					}else{
-						this.locationList =[{
-							id:1,
-							title:result.address,
-							point:{lat:e.latlng.lat,lng:e.latlng.lng}
+					} else {
+						this.locationList = [{
+							id: 1,
+							title: result.address,
+							point: {
+								lat: e.latlng.lat,
+								lng: e.latlng.lng
+							}
 						}]
 					}
-					
+
 				})
 				var marker = new BMapGL.Marker(point);
 				this.map.addOverlay(marker);
 				this.markers.push(marker);
 			});
-			// },
-			// error:err=>{
-			// 	
-			// }
-			// });
-
+	
 		}
 	}
 </script>

--
Gitblit v1.7.1