twt 3 年之前
父节点
当前提交
31a39fb80f
共有 1 个文件被更改,包括 49 次插入6 次删除
  1. 49 6
      pages/index/index.vue

+ 49 - 6
pages/index/index.vue

@@ -121,14 +121,24 @@
 				this.cityname = location.cityname;
 				this.cityCode = location.cityCode;
                 this.location=location
-
 				that.queryHomeDetail();
-
-
 			} else {
-				uni.showToast({
+				/* uni.showToast({
 					title: '请选择城市'
-				})
+				}) */
+				uni.getLocation({
+				    type: 'gcj02',
+				    success: function (res) {
+				       console.log(res)
+						that.lng=res.longitude
+						that.lat=res.latitude
+						that.getAdress();
+						
+				    },
+					 fail(err) {
+						
+					 }
+				}); 
 			}
 
 		},
@@ -200,7 +210,40 @@
 				console.log(e);
 				this.time = e.target.value
 			},
-
+            getAdress(){
+            	var location=this.lng+','+this.lat
+            	uni.request({
+            	    url: 'https://restapi.amap.com/v3/place/around', //仅为示例,并非真实接口地址。
+            	    data: {
+            	        key: '064b6a4a8ade55656edcde2f528876de',
+            			location: location,
+            			types:"190000",
+            			extensions:"all",
+            			radius:100
+            	    },
+            	    dataType: "json",
+            	    success: (res) => {
+            	        console.log(res);
+            	        this.cityname=res.data.pois[0].cityname;
+            			var cityCode=res.data.pois[0].adcode
+            			cityCode=cityCode.slice(0, -2)
+            			cityCode=cityCode+'00'
+						this.cityCode=cityCode
+            			var obj={
+            				cityname:this.cityname,
+            				lng:this.lng,
+            				lat:this.lat,
+            				cityCode:cityCode
+            			}
+            			uni.setStorage({
+            				key: 'location',
+            				data: obj,
+            				success: function () {}
+            			}); 
+            			this.queryHomeDetail();
+            	    }
+            	});
+            },
 
 
 		}