Przeglądaj źródła

是否有定位权限 + ios和安卓区别定位信息

chenrui 4 lat temu
rodzic
commit
b1a21bc45b

+ 33 - 1
libs/tools.js

@@ -404,13 +404,15 @@ export const getGpsLocation = function(callback){
 	}
 	
 	// 获取gps
+	// 获取系统信息同步接口
+	const getSystemInfo = uni.getSystemInfoSync()
 	uni.getLocation({
 		type: 'gcj02',
 		geocode: true,
 		success: function(res) {
 			console.log(res);
 			let gps = wgs84togcj02(res.longitude,res.latitude)
-			callback(gps)
+			callback(getSystemInfo.platform == 'android' ? gps : getSystemInfo.platform == 'ios' ? res : '')
 		},
 		fail: function(error){
 			console.log(error)
@@ -422,4 +424,34 @@ export const getGpsLocation = function(callback){
 			}
 		}
 	});
+}
+
+/**检查是否打开GPS功能(android)**/
+export const checkOpenGPSServiceByAndroid = () => {
+  let system = uni.getSystemInfoSync();// 获取系统信息
+  console.log(system)
+  if (system.platform === 'android') { // 判断平台
+    var context = plus.android.importClass("android.content.Context");
+    var locationManager = plus.android.importClass("android.location.LocationManager");
+    var main = plus.android.runtimeMainActivity();
+    var mainSvr = main.getSystemService(context.LOCATION_SERVICE);
+	console.log(mainSvr,'===mainSvr')
+    if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
+      uni.showModal({
+        title: '提示',
+        content: '请打开定位服务功能',
+        showCancel: false, // 不显示取消按钮
+        success() {
+          if (!mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER)) {
+            var Intent = plus.android.importClass('android.content.Intent');
+            var Settings = plus.android.importClass('android.provider.Settings');
+            var intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); 
+            main.startActivity(intent); // 打开系统设置GPS服务页面
+          } else {
+            console.log('GPS功能已开启');
+          }
+        }
+      });
+    }
+  } 
 }

+ 4 - 0
pages/myShopTour/myShopTour.vue

@@ -29,6 +29,10 @@
 									<text class="item-val" v-if="item.spendTime">{{ item.spendTime | formatTime }}</text>
 									<text class="item-val" v-else>--</text>
 								</view>
+								<view class="item-main">
+									<text class="item-tit">检查方式:</text>
+									<text class="item-val">{{ item.typeDictValue }}</text>
+								</view>
 								<u-grid class="item-grid" :col="4" hover-class="none">
 									<u-grid-item>
 										<text class="grid-num text-blue">{{item.totalTargetCount}}</text>

+ 4 - 0
pages/shopTourRecord/shopTourRecord.vue

@@ -25,6 +25,10 @@
 							<text class="item-tit">创建时间:</text>
 							<text class="item-val">{{item.startTime}}</text>
 						</view>
+						<view class="item-main">
+							<text class="item-tit">检查方式:</text>
+							<text class="item-val">{{item.typeDictValue}}</text>
+						</view>
 						<u-grid class="item-grid" :col="4" hover-class="none">
 							<u-grid-item>
 								<text class="grid-num text-blue">{{item.totalTargetCount}}</text>

+ 27 - 8
pages/signIn/signIn.vue

@@ -32,7 +32,7 @@
 
 <script>
 import { clzConfirm, saveImgToAliOss,getGpsLocation } from '@/libs/tools.js';
-import { validTaskPosition } from '@/api/task.js';
+import { validTaskPosition, tencentAddressInfo } from '@/api/task.js';
 export default {
 	data() {
 		return {
@@ -56,16 +56,36 @@ export default {
 		// 获取当前位置
 		getLocation() {
 			const _this = this;
+			// 获取系统信息同步接口
+			const res = uni.getSystemInfoSync()
 			getGpsLocation(function(gps){
 				console.log(gps)
-				_this.position = {
-					latitude:gps[1],
-					longitude:gps[0],
+				//  安卓手机需要转格式,ios不需要
+				if(res.platform == 'android'){  //  安卓
+					_this.position = { latitude: gps[1], longitude: gps[0] }
+					// 反解析拿到地址
+					_this.getAddressInfo({ lat: gps[1], lng: gps[0] })
+				}else if(res.platform == 'ios'){  //  ios
+					_this.position = { latitude: gps.latitude, longitude: gps.longitude }
+					const province = gps.address.province ? gps.address.province : ''  //  	省份名称
+					const city = gps.address.city ? gps.address.city : ''  //  城市名称
+					const district = gps.address.district ? gps.address.district : ''  //  区(县)名称
+					const poiName = gps.address.poiName ? gps.address.poiName : ''  //  POI信息
+					const street = gps.address.street ? gps.address.street : ''  //  街道信息
+					const streetNum = gps.address.streetNum ? gps.address.streetNum : ''  //  获取街道门牌号信息
+					_this.location = province + city + district + poiName + '(' + street + streetNum + ')'
 				}
-				// 反解析拿到地址
-				// this.location
 			})
 		},
+		// 根据经纬度获取具体位置
+		getAddressInfo(params) {
+			tencentAddressInfo(params).then(res => {
+				console.log(res)
+				if (res.status == 200) {
+					this.location = res.data.province + res.data.city + res.data.district + res.data.address;
+				}
+			});
+		},
 		//  签到拍照
 		goPhotograph() {
 			const _this = this;
@@ -107,8 +127,7 @@ export default {
 			}
 			// 存储当前签到信息
 			this.$u.vuex('vuex_sceneTaskSignIn',{
-				inspectorPositionAddr: '',
-				inspectorPositionPhotoBasePath:'',
+				inspectorPositionAddr: this.location,
 				inspectorPositionPhotoPath: this.photograph
 			})
 			//  判断是否超出签到范围

+ 22 - 4
pages/siteInspection/siteInspection.vue

@@ -33,7 +33,7 @@
 </template>
 
 <script>
-	import { clzConfirm,getGpsLocation } from '@/libs/tools.js'
+	import { clzConfirm, getGpsLocation, checkOpenGPSServiceByAndroid } from '@/libs/tools.js'
 	import { findStoreList } from '@/api/store.js'
 	import { queryCurrentTaskUsing, tencentAddressInfo } from '@/api/task.js'
 	export default{
@@ -51,16 +51,34 @@
 		},
 		onReady() {
 			this.getLocation()
+			// this.getAddressInfo({lng:108.9657195398708,lat:34.30901776030821})
 		},
 		methods: {
 			// 获取当前位置
 			getLocation(){
 				const _this = this
+				checkOpenGPSServiceByAndroid()
+				// 获取系统信息同步接口
+				const res = uni.getSystemInfoSync()
 				getGpsLocation(function(gps){
 					console.log(gps)
-					_this.getAddressInfo({lng:gps[0],lat:gps[1]})
-					// 按照经纬度查询
-					_this.searchHandle({lng:gps[0],lat:gps[1]})
+					//  安卓手机需要转格式,ios不需要
+					if(res.platform == 'android'){  //  安卓
+						_this.getAddressInfo({ lng: gps[0], lat: gps[1] })
+						// 按照经纬度查询
+						_this.searchHandle({ lng: gps[0], lat: gps[1] })
+					}else if(res.platform == 'ios'){  //  ios
+						const province = gps.address.province ? gps.address.province : ''  //  	省份名称
+						const city = gps.address.city ? gps.address.city : ''  //  城市名称
+						const district = gps.address.district ? gps.address.district : ''  //  区(县)名称
+						const poiName = gps.address.poiName ? gps.address.poiName : ''  //  POI信息
+						const street = gps.address.street ? gps.address.street : ''  //  街道信息
+						const streetNum = gps.address.streetNum ? gps.address.streetNum : ''  //  获取街道门牌号信息
+						_this.location = province + city + district + poiName + '(' + street + streetNum + ')'
+						// 按照经纬度查询
+						_this.searchHandle({ lng: gps.longitude, lat: gps.latitude })
+					}
+					
 				})
 			},
 			// 根据经纬度获取具体位置

Plik diff jest za duży
+ 9 - 9
unpackage/dist/dev/app-plus/app-service.js


Plik diff jest za duży
+ 14 - 14
unpackage/dist/dev/app-plus/app-view.js


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików