From e12715ffa447f0015a6715b188b8d578ea120958 Mon Sep 17 00:00:00 2001 From: duqingquan Date: Tue, 13 Sep 2022 18:33:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=85=BE=E8=AE=AF=E5=AE=9A=E4=BD=8D=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9Eapp=20key=20=E6=A0=A1=E9=AA=8C=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/SDKIntegration/SDKIntegration.vue | 11 ++++- .../utssdk/app-android/index.uts | 41 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/pages/SDKIntegration/SDKIntegration.vue b/pages/SDKIntegration/SDKIntegration.vue index 8b95a87..0fdd2c4 100644 --- a/pages/SDKIntegration/SDKIntegration.vue +++ b/pages/SDKIntegration/SDKIntegration.vue @@ -38,7 +38,9 @@ requestPremission(); }, testGetlocation:function(e){ - getLocation({ + + + let startRet = getLocation({ geocode:true, success:function(response){ console.log(response); @@ -50,6 +52,13 @@ } }) + if(!startRet){ + uni.showToast({ + title:'定位启动失败,请检查配置', + icon:'none' + }); + } + }, } } diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts b/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts index 8115b87..58e0067 100644 --- a/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts +++ b/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts @@ -12,6 +12,7 @@ import TencentLocationManager from "com.tencent.map.geolocation.TencentLocationM import TencentLocationListener from "com.tencent.map.geolocation.TencentLocationListener"; import TencentLocation from "com.tencent.map.geolocation.TencentLocation"; import TencentLocationRequest from "com.tencent.map.geolocation.TencentLocationRequest"; +import PackageManager from "android.content.pm.PackageManager"; export function requestPremission() { @@ -122,12 +123,42 @@ class SingleLocationListener extends TencentLocationListener { } +/** + * 检查定位的相关配置是否正确 + */ +function checkLocationConfig():boolean{ + + let packageName = getAppContext()!.getPackageName(); + let appInfo = getAppContext()!.getPackageManager()!.getApplicationInfo(packageName,PackageManager.GET_META_DATA) + + let metaData = appInfo.metaData + if (metaData == null) { + return false; + } + let adId = metaData.getString("TencentMapSDK") + let splitArray = adId!.split("-") + let keyCharNum = splitArray.size + + if(keyCharNum > 5){ + // 存在超过5个-,说明是符合规则的appkey + return true; + } + // 不符合校验规则,打回 + return false; +} + /** * 腾讯地图获取定位信息 * 参考文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/androidGeoAdapt */ -export function getLocation(locationOptions: LocationOptions) { +export function getLocation(locationOptions: LocationOptions):boolean { + if(!checkLocationConfig()){ + /** + * 未通过配置预校验,通常是app key 配置错误 + */ + return false + } let mLocationManager = TencentLocationManager.getInstance(getAppContext()); // 定位监听器封装 @@ -142,7 +173,11 @@ export function getLocation(locationOptions: LocationOptions) { locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO); } + console.log("requestSingleFreshLocation"); + mLocationManager.requestSingleFreshLocation(locationRequest, mLocationListener, Looper.getMainLooper()); - return { name: "getLocation"}; -} \ No newline at end of file + return true; +} + + -- GitLab