Jelajahi Sumber

商城页面获取定位

YZM 1 tahun lalu
induk
melakukan
a39a55c735
2 mengubah file dengan 112 tambahan dan 4 penghapusan
  1. 58 4
      pages/dapei/index.vue
  2. 54 0
      pages/shop/index.vue

+ 58 - 4
pages/dapei/index.vue

@@ -20,7 +20,7 @@
 					<text class="text-size-s ml-15">{{tianqiList.templow}}°c~{{tianqiList.temphigh}}°c</text>
 					<text class="text-size-s ml-15">{{tianqiList.week}}</text>
 				</view>
-				<view class="bianji" @click="bianji(1,alltouList[0].data)">{{alltouList[0].data !=0?'更换穿搭':'添加穿搭'}}</view>
+				<view v-if="alltouList[0].data !=0" class="bianji" @click="bianji(1,alltouList[0].data)">{{alltouList[0].data !=0?'更换穿搭':'添加穿搭'}}</view>
 			</view>
 			<view class="scroll-view-item_H" v-if="alltouList.length !=0">
 				<image v-if="alltouList[1].data !=0" class="chuanda" :src="alltouList[1].data.makeAppointmentCollocation.image"></image>
@@ -79,6 +79,10 @@
 </template>	
 <script>
 import{myRequest} from '@/api/request.js'
+import qqmapsdk from '../../js_sdk/qqmap-wx-jssdk.js'
+const QQMapWX = new qqmapsdk({
+	key: 'KNABZ-OAVCJ-O5IFJ-KBNST-SVIIZ-2EB3G'
+});
 export default {
 	data() {
 		return {
@@ -92,8 +96,8 @@ export default {
 			alltouList:[],
 			tianqiList:[],
 			page:1,
-			pageSize:3
-			
+			pageSize:3,
+			city:'南京'
 		};
 	},
 	onLoad(e) {
@@ -107,8 +111,58 @@ export default {
 		this.gettianqi();
 		this.getFl();
 		this.touFun();
+		this.getCity()
 	},
 	methods: {
+		getCity(){
+			var that=this;
+			uni.getLocation({
+				type: 'wgs84',
+				geocode: true,
+				success: (res) => {
+					console.log("获取经纬度成功");
+					this.latitude = res.latitude;
+					this.longitude = res.longitude;
+				},
+				fail: () => {
+					console.log("获取经纬度失败");
+				},
+				complete: () => {
+					// 解析地址
+					QQMapWX.reverseGeocoder({
+						location: {
+							latitude: this.latitude,
+							longitude: this.longitude
+						},
+						success: function(res) {
+							console.log("解析地址成功");
+							console.log(res);
+							// 省
+							let province = res.result.ad_info.province;
+							// 市
+							let city = res.result.ad_info.city;
+							//区
+							let district=res.result.ad_info.district;
+							that.city=city;
+							console.log(province);
+							console.log(city);
+							console.log(district);
+						},
+						fail: function(res) {
+							uni.showToast({
+								title: '定位失败',
+								duration: 2000,
+								icon: "none"
+							})
+							console.log(res);
+						},
+						complete: function(res) {
+							console.log(res);
+						}
+					})
+				}
+			})
+		},
 		shuaxin(){
 			this.activeIndex1=0;
 			this.page=1;
@@ -224,7 +278,7 @@ export default {
 					'Authorization':'APPCODE b838ad36bbd741ad97bbe22e50be1847'
 				},
 				data:{
-					city:'南京'
+					city:that.city
 				},
 				dataType:'json',
 				success : function(data) {

+ 54 - 0
pages/shop/index.vue

@@ -93,6 +93,10 @@
 </template>	
 <script>
 import{myRequest} from '@/api/request.js'
+import qqmapsdk from '../../js_sdk/qqmap-wx-jssdk.js'
+const QQMapWX = new qqmapsdk({
+	key: 'KNABZ-OAVCJ-O5IFJ-KBNST-SVIIZ-2EB3G'
+});
 export default {
 	data() {
 		return {
@@ -126,8 +130,58 @@ export default {
 		this.getHot();
 		this.getRecommend()
 		this.getGwc()
+		this.getCity()
 	},
 	methods: {
+		getCity(){
+			var that=this;
+			uni.getLocation({
+				type: 'wgs84',
+				geocode: true,
+				success: (res) => {
+					console.log("获取经纬度成功");
+					this.latitude = res.latitude;
+					this.longitude = res.longitude;
+				},
+				fail: () => {
+					console.log("获取经纬度失败");
+				},
+				complete: () => {
+					// 解析地址
+					QQMapWX.reverseGeocoder({
+						location: {
+							latitude: this.latitude,
+							longitude: this.longitude
+						},
+						success: function(res) {
+							console.log("解析地址成功");
+							console.log(res);
+							// 省
+							let province = res.result.ad_info.province;
+							// 市
+							let city = res.result.ad_info.city;
+							//区
+							let district=res.result.ad_info.district;
+							that.addr=[province,city,district];
+							console.log(province);
+							console.log(city);
+							console.log(district);
+						},
+						fail: function(res) {
+							uni.showToast({
+								title: '定位失败',
+								duration: 2000,
+								icon: "none"
+							})
+							console.log(res);
+						},
+						complete: function(res) {
+							console.log(res);
+						}
+					})
+				}
+			})
+		},
 		getGwc(){
 			let that = this;
 			myRequest({