wangguoyu 2 ay önce
ebeveyn
işleme
47749722de
1 değiştirilmiş dosya ile 53 ekleme ve 12 silme
  1. 53 12
      components/customMap/customMap.vue

+ 53 - 12
components/customMap/customMap.vue

@@ -60,9 +60,9 @@
 		ref
 	} from "vue"
 	import myIcon from "@/static/images/common/markIcon.png"
-import {
-	jsonp
-} from "@/utils/common.js"
+	import {
+		jsonp
+	} from "@/utils/common.js"
 
 	import {
 		onLoad,
@@ -106,8 +106,43 @@ import {
 		console.log('222222');
 		console.log('city', city);
 		const Key = `KBYBZ-FS3KZ-U2FXR-7VPDX-L7J46-23F55`
-		const url = `https://apis.map.qq.com/ws/geocoder/v1/?address=${city}&key=${Key}`;
-
+		const url = `https://apis.map.qq.com/ws/geocoder/v1`;
+		const url2 = `https://apis.map.qq.com/ws/geocoder/v1/?address=${city}&key=${Key}`;
+		// #ifdef H5
+		jsonp(url, {
+			address: `${city}`,
+			key: Key,
+			output: 'jsonp'
+		}, 'ccc1').then(res => {
+			console.log('res1222222', res);
+			if (res.status === 0) {
+			const cityLocation = res.result.location;
+			console.log('cityLocation', cityLocation);
+			if (cityLocation) {
+				data.latitude = cityLocation.lat;
+				data.longitude = cityLocation.lng;
+				data.covers[0].latitude = cityLocation.lat;
+				data.covers[0].longitude = cityLocation.lng;
+				// 重新搜索附近的地点
+				getPositionSearchByKeyword(data.keyword || '公司',
+					`nearby(${cityLocation.lat},${cityLocation.lng},1000)`,
+					onSuccess, onError, {
+						page: 1,
+						size: 3,
+					});
+			}
+			} else {
+				console.error('失败:', res);
+		
+			}
+		}).catch(err => {
+			console.log('err', err);
+		}).finally(() => {
+		
+		})
+		
+		// #endif
+		// #ifdef APP
 		uni.request({
 			url: url,
 			method: 'get',
@@ -137,7 +172,7 @@ import {
 		}).finally(() => {
 
 		})
-		return null;
+		// #endif
 	}
 
 	function handleClick() {
@@ -231,24 +266,30 @@ import {
 
 	function getCityName(latitude, longitude) {
 		const Key = `KBYBZ-FS3KZ-U2FXR-7VPDX-L7J46-23F55`
-		 const url1 = `https://apis.map.qq.com/ws/geocoder/v1?location=${latitude},${longitude}&key=${Key}&output=jsonp`;
+		const url1 = `https://apis.map.qq.com/ws/geocoder/v1?location=${latitude},${longitude}&key=${Key}&output=jsonp`;
 		const url = `https://apis.map.qq.com/ws/geocoder/v1`;
 		//const url = `https://apis.map.qq.com/ws/geocoder/v1/`;
 		// #ifdef H5
 		jsonp(url, {
 			location: `${latitude},${longitude}`,
-			key:Key,
-			output:'jsonp'
+			key: Key,
+			output: 'jsonp'
 		}, 'ccc').then(res => {
-			console.log('res', res);
+			console.log('res11111', res);
+			if (res.status === 0) {
+				const city = res.result.address_component.city;
+				currentCity.value = city; // 更新当前城市
+				console.log('当前城市:', city);
+			} else {
+				console.error('逆地理编码失败:', res);
+
+			}
 		}).catch(err => {
 			console.log('err', err);
 		}).finally(() => {
 
 		})
-
 		// #endif
-
 		// #ifdef APP
 		uni.request({
 			url: url1,