Ver Fonte

添加定位

wangchao há 3 anos atrás
pai
commit
a6d2d8d601

+ 1 - 1
components/linzq-citySelect/linzq-citySelect.vue

@@ -1,5 +1,5 @@
 <template>
 <template>
-	<div class="wrapper" :style="'top:'+statusBarHeight+'px'">
+	<div class="wrapper">
 		<div class="header">
 		<div class="header">
 <!-- 			<view class="back_div">
 <!-- 			<view class="back_div">
 				<image class="back_img" @click="back_city()" src="../../static/img/login/logo@2x.png" mode=""></image>
 				<image class="back_img" @click="back_city()" src="../../static/img/login/logo@2x.png" mode=""></image>

+ 1 - 0
manifest.json

@@ -46,6 +46,7 @@
     },
     },
     "app-plus" : {
     "app-plus" : {
         "runmode" : "liberate",
         "runmode" : "liberate",
+		"nvueStyleCompiler":"uni-app",
         "privacy" : {
         "privacy" : {
             "prompt" : "template",
             "prompt" : "template",
             "template" : {
             "template" : {

+ 104 - 30
pages/grain_pulse/position/position.vue

@@ -18,7 +18,7 @@
 					<view class="">{{address}}</view>
 					<view class="">{{address}}</view>
 					<view class="" v-if="isposition">{{text}}</view>
 					<view class="" v-if="isposition">{{text}}</view>
 				</view>
 				</view>
-				<view class="reposition Regular" @click="reloadPosition">重新定位</view>
+				<view class="reposition Regular" @click="reloadPosition">{{po_tips}}</view>
 			</view>
 			</view>
 
 
 		</view>
 		</view>
@@ -54,8 +54,10 @@
 				address: "定位失败,请点击重新定位",
 				address: "定位失败,请点击重新定位",
 				city: '营口市',
 				city: '营口市',
 				list: [],
 				list: [],
-				src: {},
-				addressObj: {}
+				position: '',
+				addressObj: {},
+				seconds: 3,
+				po_tips: '重新定位',
 			}
 			}
 		},
 		},
 		onLoad(e) {
 		onLoad(e) {
@@ -71,25 +73,30 @@
 					that.list = res.data
 					that.list = res.data
 				}
 				}
 			});
 			});
+			this.getLocation()
 			// 获取定位
 			// 获取定位
-			this.utils.getLocation().then(function(res) {
-				debugger
-				console.log("定位信息",res)
-				if (res.errMsg != "getLocation:ok") {
-					// 定位权限未开启,引导设置
-					uni.showModal({
-						title: '温馨提示',
-						content: '您已拒绝定位,请开启',
-						confirmText: '去设置',
-						success(res) {
-							if (res.confirm) {
-								//打开授权设置
-								this.utils.openSetting()
-							}
-						}
-					})
-				}
-			})
+			// this.utils.getLocation().then(function(res) {
+			// 	debugger
+			// 	console.log("定位信息",res)
+			// 	this.city = res.address.city
+			// 	this.address = res.address.poiName
+			// 	console.log('city',this.city)
+			// 	console.log('poiName',this.address)
+			// 	if (res.errMsg != "getLocation:ok") {
+			// 		// 定位权限未开启,引导设置
+			// 		uni.showModal({
+			// 			title: '温馨提示',
+			// 			content: '您已拒绝定位,请开启',
+			// 			confirmText: '去设置',
+			// 			success(res) {
+			// 				if (res.confirm) {
+			// 					//打开授权设置
+			// 					this.utils.openSetting()
+			// 				}
+			// 			}
+			// 		})
+			// 	}
+			// })
 		},
 		},
 		methods: {
 		methods: {
 			// 删除最近搜索
 			// 删除最近搜索
@@ -99,9 +106,52 @@
 					data: []
 					data: []
 				});
 				});
 			},
 			},
+			getLocation() {
+				let that = this;
+				uni.getLocation({
+					type: 'gcj02',
+					geocode: true,
+					success: function(res) {
+						console.log('获取位置数据:', res);
+						console.log('当前位置的经度:' + res.longitude);
+						console.log('当前位置的纬度:' + res.latitude);
+						//拼接当前定位回显地址
+						// #ifdef APP-PLUS
+						let _address = res.address
+						that.city = _address.city
+						that.address = _address.province + _address.city + _address.district + _address.poiName
+						console.log(that.address)
+						// #endif
+					}
+				});
+			},
 			// 重新定位
 			// 重新定位
 			reloadPosition() {
 			reloadPosition() {
-				// this.getLocation()
+				var that = this
+				that.po_tips = '定位中...'
+				let countdown = setInterval(() => {
+					that.seconds--;
+					uni.getLocation({
+						type: 'gcj02',
+						success: function(res) {
+							console.log('当前位置的经度:' + res.longitude);
+							console.log('当前位置的纬度:' + res.latitude);
+							// #ifdef APP-PLUS
+							let _address = res.address
+							that.city = _address.city
+							that.longitude = res.longitude
+							that.latitude = res.latitude
+							that.address = _address.province + _address.city + _address.district +
+								_address.poiName
+							// #endif
+						}
+					});
+					if (that.seconds <= 0) {
+						that.seconds = 3
+						that.po_tips = '重新定位'
+						clearInterval(countdown);
+					}
+				}, 1000);
 			},
 			},
 			openSetting() {
 			openSetting() {
 				// App跳转系统的设置界面
 				// App跳转系统的设置界面
@@ -148,20 +198,32 @@
 			},
 			},
 			// 搜索
 			// 搜索
 			searchAddress(val) {
 			searchAddress(val) {
-				console.log(val)
+				// console.log(val)
 				let that = this;
 				let that = this;
 				uni.chooseLocation({
 				uni.chooseLocation({
 					success: function(res) {
 					success: function(res) {
-						console.log('位置名称:' + res.name);
-						console.log('详细地址:' + res.address);
-						console.log('纬度:' + res.latitude);
-						console.log('经度:' + res.longitude);
+						console.log(res)
+						// console.log('位置名称:' + res.name);
+						// console.log('详细地址:' + res.address);
+						// console.log('纬度:' + res.latitude);
+						// console.log('经度:' + res.longitude);
 						that.list.push(res.name)
 						that.list.push(res.name)
-						this.src = res
+						this.position = res.name
 						uni.setStorage({
 						uni.setStorage({
 							key: 'SearchList_key',
 							key: 'SearchList_key',
 							data: that.list
 							data: that.list
 						});
 						});
+						debugger
+						uni.setStorage({
+							key: 'setLocaltion',
+							data: res.name,
+							success() {
+								uni.switchTab({
+									url: "../home"
+								});
+							}
+
+						})
 					}
 					}
 				});
 				});
 
 
@@ -173,8 +235,20 @@
 				})
 				})
 			},
 			},
 			toHome(item) {
 			toHome(item) {
-				uni.navigateTo({
-					url: "../home?src=" + this.src
+				console.log("跳转首页")
+				uni.setStorage({
+					key: 'setLocaltion',
+					data: item,
+					success() {
+						uni.switchTab({
+							url: "../home",
+							success(e) {
+								console.log(e)
+
+							}
+						});
+					}
+
 				})
 				})
 			}
 			}
 		}
 		}