Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
Hello UTS
提交
7fff25b4
H
Hello UTS
项目概览
DCloud
/
Hello UTS
通知
1595
Star
27
Fork
9
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
2
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
Hello UTS
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
2
Issue
2
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
7fff25b4
编写于
9月 07, 2022
作者:
杜庆泉
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
腾讯地图 单次定位实现
上级
65a36c01
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
32 deletion
+67
-32
pages/SDKIntegration/SDKIntegration.vue
pages/SDKIntegration/SDKIntegration.vue
+16
-7
uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts
...dules/uts-tencentgeolocation/utssdk/app-android/index.uts
+51
-25
未找到文件。
pages/SDKIntegration/SDKIntegration.vue
浏览文件 @
7fff25b4
...
...
@@ -2,7 +2,8 @@
<view>
<page-head
:title=
"title"
></page-head>
<view
class=
"uni-btn-v uni-common-mt"
>
<button
type=
"primary"
@
tap=
"testGetlocation"
>
获取定位信息
</button>
<button
type=
"primary"
@
tap=
"checkLocationPermission"
>
请求定位权限
</button>
<button
type=
"primary"
@
tap=
"testGetlocation"
>
获取定位信息(需自定义基座)
</button>
</view>
</view>
</
template
>
...
...
@@ -13,16 +14,24 @@
export
default
{
data
()
{
return
{
title
:
'
SDK集成示例
-开发中
'
,
title
:
'
SDK集成示例
'
,
}
},
methods
:
{
testGetlocation
:
function
(
e
){
checkLocationPermission
:
function
(
e
){
requestPremission
();
var
locationRet
=
getLocation
(
function
(
res
){
console
.
log
(
res
);
});
},
testGetlocation
:
function
(
e
){
getLocation
({
onLocationChanged
:
function
(
locationName
,
locationAddress
){
var
addressDesc
=
locationAddress
+
'
-
'
+
locationName
uni
.
showToast
({
title
:
'
执行结果:
'
+
addressDesc
,
icon
:
'
none
'
});
}
})
},
}
...
...
uni_modules/uts-tencentgeolocation/utssdk/app-android/index.uts
浏览文件 @
7fff25b4
...
...
@@ -15,57 +15,83 @@ import TencentLocation from "com.tencent.map.geolocation.TencentLocation";
export function requestPremission() {
// 注册一个请求回调
// onAppActivityRequestPermissionsResult((requestCode: number,
// permissions: Array<string>,
// grantResults: Array<number>) => {
// let eventName = "onAppActivityRequestPermissionsResult - " + Date.now();
// console.log(eventName);
// });
//发起权限申请
// let permissions:string[] = [Manifest.permission.ACCESS_COARSE_LOCATION]
onAppActivityRequestPermissionsResult((requestCode: number,
permissions: MutableList<string>,
grantResults: MutableList<number>) => {
/**
* 0 已同意
* -1 已拒绝
*/
console.log(grantResults);
console.log(permissions);
console.log(requestCode);
});
// 发起权限申请
// 参考文档:https://lbs.qq.com/mobile/androidLocationSDK/androidGeoGuide/androidGeoAdapt
ActivityCompat.requestPermissions(
getUniActivity()!,
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION), 1001);
arrayOf(Manifest.permission.ACCESS_COARSE_LOCATION
,Manifest.permission.ACCESS_FINE_LOCATION
), 1001);
// 请求权限
return { name: "requestPremission"};
}
type LocationOptions = {
onLocationChanged: (locationName:string,locationAddress:string ) => void;
};
class LocationOptionsWapper{
hostOption:LocationOptions;
constructor(option: LocationOptions){
this.hostOption = option
}
onLocationChanged(location:TencentLocation , error:Int ,
reason:string){
hostOption.onLocationChanged(location.name,location.address);
}
onStatusUpdate(name:string, status:Int, desc:string){
//hostOption.onStatusUpdate(name,status,desc);
}
};
class SingleLocationListener extends TencentLocationListener {
constructor(changeListener: (res: string) => void){
hostOptionWraper:LocationOptionsWapper;
constructor(option: LocationOptionsWapper){
super();
this.hostOptionWraper = option
}
override onLocationChanged(location:TencentLocation , error:Int ,
reason:string ):void{
if(error == 0){
let locationName = location.name;
let locationAddress = location.address;
let latitude = location.latitude;
let longitude = location.longitude;
}
console.log(location);
console.log(error);
console.log(reason);
this.hostOptionWraper.onLocationChanged(location,error,reason);
}
override onStatusUpdate(name:string, status:Int, desc:string ):void{
console.log(name
);
this.hostOptionWraper.onStatusUpdate(name,status,desc
);
}
}
export function getLocation(changeListener:
(res: string) => void
) {
export function getLocation(changeListener:
LocationOptions
) {
// 获取当前的地址回调
let mLocationManager = TencentLocationManager.getInstance(getAppContext());
let mLocationListener = new SingleLocationListener( function(newRes:string){
changeListener(newRes);
});
let locationOptionWrapper = new LocationOptionsWapper(changeListener);
let mLocationListener = new SingleLocationListener(locationOptionWrapper);
mLocationManager.requestSingleFreshLocation(null, mLocationListener, Looper.getMainLooper());
// 请求权限
return { name: "getLocation"};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录