wangguoyu 2 tháng trước cách đây
mục cha
commit
a93b94284f
1 tập tin đã thay đổi với 34 bổ sung6 xóa
  1. 34 6
      components/customMap/customMap.vue

+ 34 - 6
components/customMap/customMap.vue

@@ -15,9 +15,10 @@
 			:markers="data.covers" :show-location="true"> </map>
 
 		<view v-if="result" class="map-card-list">
-			<view v-for="(item,index) in result.data.data" key="index"  @click="xuanzeAdress(item)" class="map-card-box">
+			<view v-for="(item,index) in result.data.data" key="index" @click="xuanzeAdress(item)" class="map-card-box">
 				<view>
-					<view class="map-card-title"><text v-if="index==0" class="dqwz-text">当前位置</text>{{item.title}}</view>
+					<view class="map-card-title"><text v-if="index==0" class="dqwz-text">当前位置</text>{{item.title}}
+					</view>
 					<view class="map-card-address">{{item.address}}</view>
 				</view>
 				<icon class="map-active-icon" v-if="index==0"></icon>
@@ -60,9 +61,29 @@
 		}
 	}
 
-	function onSuccess(data) {
-		console.log('数据', data);
-		result.value = data
+	function onSuccess(res) {
+		console.log('数据', res);
+		result.value = res
+		if (res.data && res.data.data && res.data.data.length > 0) {
+					// 获取第一个搜索结果的经纬度
+					const firstResult = res.data.data[0];
+					const newLatitude = firstResult.location.lat; // 纬度
+					const newLongitude = firstResult.location.lng; // 经度
+		
+					// 更新地图的中心点
+					data.latitude = newLatitude;
+					data.longitude = newLongitude;
+		
+					// 更新标记点
+					data.covers = [{
+						latitude: newLatitude,
+						longitude: newLongitude,
+						iconPath: myIcon, // 使用你的图标路径
+						width: 30,
+						height: 30
+					}];
+				}
+		
 	}
 
 	function onError(err) {
@@ -74,9 +95,10 @@
 		emits('close');
 
 	}
+
 	function xuanzeAdress(item) {
 		console.log('item');
-		emits('xuanzeAdress',item.address);
+		emits('xuanzeAdress', item.address);
 
 	}
 
@@ -108,6 +130,12 @@
 				data.covers[0].latitude = res.latitude;
 				console.log('当前位置的经度:' + res.longitude);
 				console.log('当前位置的纬度:' + res.latitude);
+				// 获取当前位置附近的数据
+				getPositionSearchByKeyword('公司', `nearby(${res.latitude},${res.longitude},1000)`, onSuccess,
+					onError, {
+						page: 1,
+						size: 3,
+					});
 			}
 		});
 	}