diff --git a/pages/SDKIntegration/SDKIntegration.vue b/pages/SDKIntegration/SDKIntegration.vue index 39a909d0d31f1c9560878fbcf19bd8a3db25fa01..59535f7797a8c329d7cb655dc2367c95dac1d2b5 100644 --- a/pages/SDKIntegration/SDKIntegration.vue +++ b/pages/SDKIntegration/SDKIntegration.vue @@ -24,8 +24,10 @@ }, testGetlocation:function(e){ getLocation({ - onLocationChanged:function(locationName,locationAddress){ - var addressDesc = locationAddress + '-' + locationName + geocode:true, + success:function(response){ + console.log(response); + var addressDesc = response.name + '-' + response.address uni.showToast({ title:'执行结果:' + addressDesc, icon:'none' diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-android/config.json b/uni_modules/uts-tencentgeolocation/utssdk/app-android/config.json index 99bddc8f8c93a544554d5c67461c7933ea7f9348..ed0465734a509323fa8589de0e33fb39f45b52b3 100644 --- a/uni_modules/uts-tencentgeolocation/utssdk/app-android/config.json +++ b/uni_modules/uts-tencentgeolocation/utssdk/app-android/config.json @@ -1,9 +1,9 @@ { - "libs": [], "dependencies": [{ "id": "androidx.core:core", "source": "implementation 'androidx.core:core:1.0.0'" - }, { + }, + { "id": "com.tencent.map.geolocation:TencentLocationSdk-openplatform", "source": "implementation 'com.tencent.map.geolocation:TencentLocationSdk-openplatform:7.3.0'" }], diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts b/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts index 637d9d8fc5dcffd919c3655a8aa4a467fc904045..8c71d473018fdfc2f3596e1eb414bc8ba181b813 100644 --- a/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts +++ b/uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts @@ -11,6 +11,8 @@ import Looper from "android.os.Looper"; import TencentLocationManager from "com.tencent.map.geolocation.TencentLocationManager"; import TencentLocationListener from "com.tencent.map.geolocation.TencentLocationListener"; import TencentLocation from "com.tencent.map.geolocation.TencentLocation"; +import TencentLocationRequest from "com.tencent.map.geolocation.TencentLocationRequest"; + export function requestPremission() { @@ -27,7 +29,7 @@ export function requestPremission() { console.log(requestCode); }); // 发起权限申请 - // 参考文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/androidGeoAdapt + ActivityCompat.requestPermissions( getUniActivity()!, arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION), 1001); @@ -37,11 +39,24 @@ export function requestPremission() { } - +/** + * 定位请求参数封装 + */ type LocationOptions = { - onLocationChanged: (locationName:string,locationAddress:string ) => void; + geocode:boolean, + success: (response:LocationResponse) => void; }; +/** + * 定位返回结果封装 + */ +type LocationResponse = { + name?:string, + address?:string, + latitude?:number, + longitude?:number +} + class LocationOptionsWapper{ hostOption:LocationOptions; @@ -53,16 +68,25 @@ class LocationOptionsWapper{ onLocationChanged(location:TencentLocation , error:Int , reason:string){ - hostOption.onLocationChanged(location.name,location.address); + let response = new LocationResponse(); + response.name = location.name; + response.address = location.address; + response.latitude = location.latitude; + response.longitude = location.longitude; + this.hostOption.success(response); } onStatusUpdate(name:string, status:Int, desc:string){ + // 定位状态发生变化 //hostOption.onStatusUpdate(name,status,desc); } }; +/** + * Tencent 定位监听实现类 + */ class SingleLocationListener extends TencentLocationListener { @@ -75,7 +99,6 @@ class SingleLocationListener extends TencentLocationListener { override onLocationChanged(location:TencentLocation , error:Int , reason:string ):void{ - this.hostOptionWraper.onLocationChanged(location,error,reason); } @@ -85,14 +108,25 @@ class SingleLocationListener extends TencentLocationListener { } -export function getLocation(changeListener: LocationOptions) { +/** + * 腾讯地图获取定位信息 + * 参考文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/androidGeoAdapt + */ +export function getLocation(locationOptions: LocationOptions) { - // 获取当前的地址回调 let mLocationManager = TencentLocationManager.getInstance(getAppContext()); - let locationOptionWrapper = new LocationOptionsWapper(changeListener); + // 定位监听器封装 + let locationOptionWrapper = new LocationOptionsWapper(locationOptions); let mLocationListener = new SingleLocationListener(locationOptionWrapper); - - mLocationManager.requestSingleFreshLocation(null, mLocationListener, Looper.getMainLooper()); - // 请求权限 + // 发起单次请求 + let locationRequest = TencentLocationRequest.create() + // 是否需要逆地理编码 + if(locationOptions.geocode){ + locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_ADMIN_AREA); + }else{ + locationRequest.setRequestLevel(TencentLocationRequest.REQUEST_LEVEL_GEO); + } + + mLocationManager.requestSingleFreshLocation(locationRequest, mLocationListener, Looper.getMainLooper()); return { name: "getLocation"}; } \ No newline at end of file diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSDK-v7.4.9.jar b/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSDK-v7.4.9.jar deleted file mode 100644 index afaf663efad2fe8be5d9ef17cbb9351291a5029a..0000000000000000000000000000000000000000 Binary files a/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSDK-v7.4.9.jar and /dev/null differ diff --git a/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSdk-openplatform-7.4.9.aar b/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSdk-openplatform-7.4.9.aar new file mode 100644 index 0000000000000000000000000000000000000000..ba46ee79f1e03cbeccbc1dd7159b7d2f649ad029 Binary files /dev/null and b/uni_modules/uts-tencentgeolocation/utssdk/app-android/libs/TencentLocationSdk-openplatform-7.4.9.aar differ