Sfoglia il codice sorgente

优化定位逻辑

xiaoxin 2 anni fa
parent
commit
e7807fcf1e

+ 37 - 53
pagesClockIn/home/home.vue

@@ -82,8 +82,6 @@
 </template>
 </template>
 
 
 <script>
 <script>
-var QQMapWX = require('../util/qqmap-wx-jssdk1.1/qqmap-wx-jssdk')
-var qqmapsdk
 export default {
 export default {
 	data() {
 	data() {
 		return {
 		return {
@@ -128,17 +126,14 @@ export default {
 			// 是否需要拍摄场景照片
 			// 是否需要拍摄场景照片
 			takePicture: true,
 			takePicture: true,
 			// 刷新定位定时器
 			// 刷新定位定时器
-			timer2: null
+			timer2: null,
+			// 密匙
+			key: 'a9757735c230c231ea1c61c02c80dac1'
 		}
 		}
 	},
 	},
 	onLoad() {
 	onLoad() {
 		// 获取用户的个人信息数据
 		// 获取用户的个人信息数据
 		this.getUserInfo()
 		this.getUserInfo()
-		// 实例化API核心类
-		qqmapsdk = new QQMapWX({
-			// 申请的key
-			key: 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
-		})
 		// 获取当前系统时间
 		// 获取当前系统时间
 		this.getNowTime()
 		this.getNowTime()
 	},
 	},
@@ -161,10 +156,6 @@ export default {
 	onPullDownRefresh() {
 	onPullDownRefresh() {
 		uni.removeStorageSync('manager')
 		uni.removeStorageSync('manager')
 		uni.removeStorageSync('sub-administrator')
 		uni.removeStorageSync('sub-administrator')
-		qqmapsdk = new QQMapWX({
-			// 申请的key
-			key: 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
-		})
 		if (this.timer2) {
 		if (this.timer2) {
 			clearInterval(this.timer2)
 			clearInterval(this.timer2)
 		}
 		}
@@ -286,30 +277,28 @@ export default {
 				title: '定位中,请稍后',
 				title: '定位中,请稍后',
 				mask: true
 				mask: true
 			})
 			})
-			qqmapsdk.reverseGeocoder({
+
+			// 获取经纬度
+			uni.getLocation({
+				type: 'gcj02',
 				success: (res) => {
 				success: (res) => {
-					// console.log(res);
-					if (res.status == 0) {
-						// 获取详细地址信息 经纬度
-						this.address = res.result.address
-						this.myLat = res.result.location.lat
-						this.myLng = res.result.location.lng
-						// 获取当天的打卡列表数组
-						this.getRulesList()
-					} else {
-						uni.showToast({
-							title: '请求定位失败',
-							icon: 'none'
-						})
-					}
-				},
-				fail: (error) => {
-					uni.getLocation({
-						type: 'gcj02',
+					// console.log('当前位置的经度:' + res.longitude)
+					// console.log('当前位置的纬度:' + res.latitude)
+					this.myLat = res.latitude
+					this.myLng = res.longitude
+
+					// 获取详细地址
+					uni.request({
+						url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':1}&type=geocode&tk=${this.key}`,
 						success: (res) => {
 						success: (res) => {
-							this.myLat = res.latitude
-							this.myLng = res.longitude
+							// console.log(res)
+							this.address = res.data.result.formatted_address
+						},
+						fail: () => {
 							this.address = '未知地址'
 							this.address = '未知地址'
+						},
+						complete: () => {
+							// 获取当天的打卡列表数组
 							this.getRulesList()
 							this.getRulesList()
 						}
 						}
 					})
 					})
@@ -388,30 +377,25 @@ export default {
 			if (this.timer2) {
 			if (this.timer2) {
 				clearInterval(this.timer2)
 				clearInterval(this.timer2)
 			}
 			}
+
 			this.timer2 = setInterval(() => {
 			this.timer2 = setInterval(() => {
-				qqmapsdk.reverseGeocoder({
+				uni.getLocation({
+					type: 'gcj02',
 					success: (res) => {
 					success: (res) => {
-						if (res.status == 0) {
-							// 获取详细地址信息 经纬度
-							this.address = res.result.address
-							this.myLat = res.result.location.lat
-							this.myLng = res.result.location.lng
-							this.getTimestamp()
-							this.changeType()
-						} else {
-							uni.showToast({
-								title: '请求定位失败',
-								icon: 'none'
-							})
-						}
-					},
-					fail: (error) => {
-						uni.getLocation({
-							type: 'gcj02',
+						this.myLat = res.latitude
+						this.myLng = res.longitude
+
+						// 获取详细地址
+						uni.request({
+							url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':1}&type=geocode&tk=${this.key}`,
 							success: (res) => {
 							success: (res) => {
-								this.myLat = res.latitude
-								this.myLng = res.longitude
+								// console.log(res)
+								this.address = res.data.result.formatted_address
+							},
+							fail: () => {
 								this.address = '未知地址'
 								this.address = '未知地址'
+							},
+							complete: () => {
 								this.getTimestamp()
 								this.getTimestamp()
 								this.changeType()
 								this.changeType()
 							}
 							}

+ 25 - 32
pagesClockIn/location/location.vue

@@ -38,8 +38,6 @@
 </template>
 </template>
 
 
 <script>
 <script>
-var QQMapWX = require('../util/qqmap-wx-jssdk1.1/qqmap-wx-jssdk')
-var qqmapsdk
 export default {
 export default {
 	data() {
 	data() {
 		return {
 		return {
@@ -66,50 +64,45 @@ export default {
 			// 规则id
 			// 规则id
 			id: '',
 			id: '',
 			// 弹窗当前时间
 			// 弹窗当前时间
-			nowTime_pop: ''
+			nowTime_pop: '',
+			// 密匙
+			key: 'a9757735c230c231ea1c61c02c80dac1'
 		}
 		}
 	},
 	},
 	onLoad(options) {
 	onLoad(options) {
 		let obj = JSON.parse(options.obj)
 		let obj = JSON.parse(options.obj)
 		this.timeRange = obj.timeRange
 		this.timeRange = obj.timeRange
 		this.id = obj.id
 		this.id = obj.id
-		// 实例化API核心类
-		qqmapsdk = new QQMapWX({
-			// 申请的key
-			key: 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
-		})
 		this.getLocationData()
 		this.getLocationData()
 	},
 	},
 	methods: {
 	methods: {
 		// 获取定位具体信息
 		// 获取定位具体信息
 		getLocationData() {
 		getLocationData() {
-			qqmapsdk.reverseGeocoder({
+			uni.getLocation({
+				type: 'gcj02',
 				success: (res) => {
 				success: (res) => {
-					// console.log(res);
-					if (res.status == 0) {
-						// 获取详细地址信息
-						this.address = res.result.address
-						// 获取地址经纬度
-						this.latitude = res.result.location.lat
-						this.longitude = res.result.location.lng
-						// 获取标记点地址经纬度
-						this.covers[0].latitude = res.result.location.lat
-						this.covers[0].longitude = res.result.location.lng
-					} else {
-						uni.getLocation({
-							type: 'gcj02',
-							success: (res) => {
-								this.latitude = res.latitude
-								this.longitude = res.longitude
-								this.address = '未知地址'
-								this.covers[0].latitude = res.latitude
-								this.covers[0].longitude = res.longitude
-							}
-						})
-					}
+					// 获取地址经纬度
+					this.latitude = res.latitude
+					this.longitude = res.longitude
+					// 获取标记点地址经纬度
+					this.covers[0].latitude = res.latitude
+					this.covers[0].longitude = res.longitude
+
+					// 获取详细地址
+					uni.request({
+						url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':1}&type=geocode&tk=${this.key}`,
+						success: (res) => {
+							// console.log(res)
+							this.address = res.data.result.formatted_address
+						},
+						fail: () => {
+							this.address = '未知地址'
+						}
+					})
 				}
 				}
 			})
 			})
 		},
 		},
+
 		// 点击刷新按钮回调
 		// 点击刷新按钮回调
 		handleRefresh() {
 		handleRefresh() {
 			uni.showLoading({
 			uni.showLoading({
@@ -370,4 +363,4 @@ export default {
 		}
 		}
 	}
 	}
 }
 }
-</style>
+</style>

+ 33 - 42
pagesRepairs/selectArea/selectArea.vue

@@ -27,8 +27,6 @@
 </template>
 </template>
 
 
 <script>
 <script>
-var QQMapWX = require('../util/qqmap-wx-jssdk1.1/qqmap-wx-jssdk')
-var qqmapsdk
 export default {
 export default {
 	data() {
 	data() {
 		return {
 		return {
@@ -54,18 +52,11 @@ export default {
 			areaTreeList: [],
 			areaTreeList: [],
 			// 校区数组
 			// 校区数组
 			schoolList: [],
 			schoolList: [],
-			// 用户定位经度
-			myLng: 0,
-			// 用户定位纬度
-			myLat: 0
+			// 密匙
+			key: 'ee7d39a2cc41bd2ffca08d3aa3fe5fe5'
 		}
 		}
 	},
 	},
 	onLoad(options) {
 	onLoad(options) {
-		// 实例化API核心类
-		qqmapsdk = new QQMapWX({
-			// 申请的key
-			key: 'X57BZ-ZISE3-KTN3O-3P45H-C3J7Q-D5B67'
-		})
 		if (options.schoolId) {
 		if (options.schoolId) {
 			this.schoolId = options.schoolId
 			this.schoolId = options.schoolId
 			this.buildId = options.buildId
 			this.buildId = options.buildId
@@ -80,43 +71,43 @@ export default {
 				title: '定位中,请稍后',
 				title: '定位中,请稍后',
 				mask: true
 				mask: true
 			})
 			})
-			qqmapsdk.reverseGeocoder({
+
+			uni.getLocation({
+				type: 'gcj02',
 				success: (res) => {
 				success: (res) => {
-					// console.log(res)
-					if (res.status === 0) {
-						let address = res.result.address
-						// console.log(address)
-						if (address.indexOf('南昌市') !== -1) {
-							this.current = 0
-						} else {
-							this.current = 1
-						}
-						this.schoolId = this.schoolList[this.current].id
-						this.getRepairAreaTree()
-					} else {
-						uni.showToast({
-							title: '请求定位失败',
-							icon: 'none'
-						})
-					}
-				},
-				fail: (error) => {
-					uni.showModal({
-						title: '提示',
-						content: '定位失败,请手动选择校区',
-						showCancel: false,
-						confirmText: '确定',
+					// 获取详细地址
+					uni.request({
+						url: `https://api.tianditu.gov.cn/geocoder?postStr={'lon':${res.longitude},'lat':${res.latitude},'ver':1}&type=geocode&tk=${this.key}`,
 						success: (res) => {
 						success: (res) => {
-							if (res.confirm) {
+							// console.log(res)
+							let address = res.data.result.formatted_address
+							if (address.indexOf('南昌市') !== -1) {
 								this.current = 0
 								this.current = 0
-								this.schoolId = this.schoolList[this.current].id
-								this.getRepairAreaTree()
+							} else {
+								this.current = 1
 							}
 							}
+							this.schoolId = this.schoolList[this.current].id
+							this.getRepairAreaTree()
+						},
+						fail: () => {
+							uni.showModal({
+								title: '提示',
+								content: '定位失败,请手动选择校区',
+								showCancel: false,
+								confirmText: '确定',
+								success: (res) => {
+									if (res.confirm) {
+										this.current = 0
+										this.schoolId = this.schoolList[this.current].id
+										this.getRepairAreaTree()
+									}
+								}
+							})
+						},
+						complete: () => {
+							uni.hideLoading()
 						}
 						}
 					})
 					})
-				},
-				complete: () => {
-					uni.hideLoading()
 				}
 				}
 			})
 			})
 		},
 		},